Wire everything up
This commit is contained in:
@@ -114,13 +114,13 @@ func (o *Orchestrator) processCharacter(char types.Character) {
|
||||
logger.Info("Orchestrator.processCharacter: Starting processing for character: %s (ID: %d)", char.CharacterName, char.ID)
|
||||
|
||||
// Get extractors for this character
|
||||
logger.Info("Orchestrator.processCharacter: Getting extractors for character %s", char.CharacterName)
|
||||
extractors, err := routes.GetExtractorsForCharacter(o.esiClient, int(char.ID), char.AccessToken)
|
||||
if err != nil {
|
||||
logger.Warning("Orchestrator.processCharacter: Failed to get extractors for character %s: %v", char.CharacterName, err)
|
||||
return
|
||||
}
|
||||
logger.Info("Orchestrator.processCharacter: Got %d extractors for character %s", len(extractors), char.CharacterName)
|
||||
// logger.Info("Orchestrator.processCharacter: Getting extractors for character %s", char.CharacterName)
|
||||
// extractors, err := routes.GetExtractorsForCharacter(o.esiClient, int(char.ID), char.AccessToken)
|
||||
// if err != nil {
|
||||
// logger.Warning("Orchestrator.processCharacter: Failed to get extractors for character %s: %v", char.CharacterName, err)
|
||||
// return
|
||||
// }
|
||||
// logger.Info("Orchestrator.processCharacter: Got %d extractors for character %s", len(extractors), char.CharacterName)
|
||||
|
||||
// Get storage for this character
|
||||
logger.Info("Orchestrator.processCharacter: Getting storage for character %s", char.CharacterName)
|
||||
@@ -136,8 +136,8 @@ func (o *Orchestrator) processCharacter(char types.Character) {
|
||||
o.checkStorageThresholds(char.CharacterName, storage)
|
||||
|
||||
// Update expiry timers for extractors
|
||||
logger.Info("Orchestrator.processCharacter: Updating expiry timers for character %s", char.CharacterName)
|
||||
o.updateExpiryTimers(char.CharacterName, extractors)
|
||||
// logger.Info("Orchestrator.processCharacter: Updating expiry timers for character %s", char.CharacterName)
|
||||
// o.updateExpiryTimers(char.CharacterName, extractors)
|
||||
|
||||
logger.Info("Orchestrator.processCharacter: Completed processing for character %s", char.CharacterName)
|
||||
}
|
||||
|
||||
@@ -27,65 +27,59 @@ type StorageInfo struct {
|
||||
}
|
||||
|
||||
// GetExtractorsForCharacter retrieves extractor information for a character
|
||||
func GetExtractorsForCharacter(esiClient esi.ESIInterface, characterID int, accessToken string) ([]ExtractorInfo, error) {
|
||||
func GetExtractorsForCharacter(esiClient esi.ESIInterface, characterID int, accessToken string, planetIDs []int64) ([]ExtractorInfo, error) {
|
||||
logger.Info("GetExtractorsForCharacter: Starting for character ID %d", characterID)
|
||||
|
||||
// Get character planets
|
||||
planets, err := esiClient.GetCharacterPlanets(context.Background(), characterID, accessToken)
|
||||
if err != nil {
|
||||
logger.Error("GetExtractorsForCharacter: Failed to get planets for character %d: %v", characterID, err)
|
||||
return nil, err
|
||||
}
|
||||
logger.Info("GetExtractorsForCharacter: Found %d planets for character %d", len(planets), characterID)
|
||||
logger.Info("GetExtractorsForCharacter: Found %d planets for character %d", len(planetIDs), characterID)
|
||||
|
||||
var extractors []ExtractorInfo
|
||||
|
||||
for i, planet := range planets {
|
||||
logger.Info("GetExtractorsForCharacter: Processing planet %d/%d (ID: %d)", i+1, len(planets), planet.PlanetID)
|
||||
for i, planetID := range planetIDs {
|
||||
logger.Info("GetExtractorsForCharacter: Processing planet %d/%d (ID: %d)", i+1, len(planetIDs), planetID)
|
||||
|
||||
// Get planet details
|
||||
details, err := esiClient.GetPlanetDetails(context.Background(), characterID, planet.PlanetID, accessToken)
|
||||
details, err := esiClient.GetPlanetPI(context.Background(), characterID, planetID, accessToken)
|
||||
if err != nil {
|
||||
logger.Warning("GetExtractorsForCharacter: Failed to fetch details for planet %d: %v", planet.PlanetID, err)
|
||||
logger.Warning("GetExtractorsForCharacter: Failed to fetch details for planet %d: %v", planetID, err)
|
||||
continue
|
||||
}
|
||||
logger.Info("GetExtractorsForCharacter: Got planet details for planet %d with %d pins", planet.PlanetID, len(details.Pins))
|
||||
logger.Info("GetExtractorsForCharacter: Got planet details for planet %d with %d pins", planetID, len(details.Pins))
|
||||
|
||||
if details != nil {
|
||||
// Get planet name from universe endpoint
|
||||
planetNameData, err := esiClient.GetPlanetName(context.Background(), planet.PlanetID)
|
||||
planetNameData, err := esiClient.GetPlanetName(context.Background(), planetID)
|
||||
if err != nil {
|
||||
logger.Error("GetExtractorsForCharacter: Failed to get planet name for planet ID %d: %v", planet.PlanetID, err)
|
||||
logger.Error("GetExtractorsForCharacter: Failed to get planet name for planet ID %d: %v", planetID, err)
|
||||
continue
|
||||
}
|
||||
logger.Info("GetExtractorsForCharacter: Planet %d name: %s", planet.PlanetID, planetNameData.Name)
|
||||
logger.Info("GetExtractorsForCharacter: Planet %d name: %s", planetID, planetNameData.Name)
|
||||
|
||||
// Count extractors and get expiry dates
|
||||
extractorCount := 0
|
||||
for j, pin := range details.Pins {
|
||||
logger.Info("GetExtractorsForCharacter: Processing pin %d/%d (TypeID: %d) on planet %s", j+1, len(details.Pins), pin.TypeID, planetNameData.Name)
|
||||
// for j, pin := range details.Pins {
|
||||
// logger.Info("GetExtractorsForCharacter: Processing pin %d/%d (TypeID: %d) on planet %s", j+1, len(details.Pins), pin.TypeID, planetNameData.Name)
|
||||
|
||||
if pin.ExtractorDetails != nil {
|
||||
logger.Info("GetExtractorsForCharacter: Found extractor (TypeID: %d) on planet %s", pin.TypeID, planetNameData.Name)
|
||||
extractorCount++
|
||||
expiryDate := "N/A"
|
||||
if pin.ExpiryTime != nil {
|
||||
expiryDate = *pin.ExpiryTime
|
||||
logger.Info("GetExtractorsForCharacter: Extractor expiry: %s", expiryDate)
|
||||
} else {
|
||||
logger.Info("GetExtractorsForCharacter: Extractor has no expiry time")
|
||||
}
|
||||
// if pin.ExtractorDetails != nil {
|
||||
// logger.Info("GetExtractorsForCharacter: Found extractor (TypeID: %d) on planet %s", pin.TypeID, planetNameData.Name)
|
||||
// extractorCount++
|
||||
// expiryDate := "N/A"
|
||||
// if pin.ExpiryTime != nil {
|
||||
// expiryDate = *pin.ExpiryTime
|
||||
// logger.Info("GetExtractorsForCharacter: Extractor expiry: %s", expiryDate)
|
||||
// } else {
|
||||
// logger.Info("GetExtractorsForCharacter: Extractor has no expiry time")
|
||||
// }
|
||||
|
||||
extractors = append(extractors, ExtractorInfo{
|
||||
PlanetName: planetNameData.Name,
|
||||
ExtractorNumber: extractorCount,
|
||||
ExpiryDate: expiryDate,
|
||||
})
|
||||
logger.Info("GetExtractorsForCharacter: Added extractor %d to results", extractorCount)
|
||||
} else {
|
||||
logger.Info("GetExtractorsForCharacter: Pin %d is not an extractor (TypeID: %d)", j+1, pin.TypeID)
|
||||
}
|
||||
}
|
||||
// extractors = append(extractors, ExtractorInfo{
|
||||
// PlanetName: planetNameData.Name,
|
||||
// ExtractorNumber: extractorCount,
|
||||
// ExpiryDate: expiryDate,
|
||||
// })
|
||||
// logger.Info("GetExtractorsForCharacter: Added extractor %d to results", extractorCount)
|
||||
// } else {
|
||||
// logger.Info("GetExtractorsForCharacter: Pin %d is not an extractor (TypeID: %d)", j+1, pin.TypeID)
|
||||
// }
|
||||
// }
|
||||
logger.Info("GetExtractorsForCharacter: Found %d extractors on planet %s", extractorCount, planetNameData.Name)
|
||||
}
|
||||
}
|
||||
@@ -112,7 +106,7 @@ func GetStorageForCharacter(esiClient esi.ESIInterface, characterID int, accessT
|
||||
logger.Info("GetStorageForCharacter: Processing planet %d/%d (ID: %d)", i+1, len(planets), planet.PlanetID)
|
||||
|
||||
// Get planet details
|
||||
details, err := esiClient.GetPlanetDetails(context.Background(), characterID, planet.PlanetID, accessToken)
|
||||
details, err := esiClient.GetPlanetPI(context.Background(), characterID, planet.PlanetID, accessToken)
|
||||
if err != nil {
|
||||
logger.Warning("GetStorageForCharacter: Failed to fetch details for planet %d: %v", planet.PlanetID, err)
|
||||
continue
|
||||
@@ -141,7 +135,7 @@ func GetStorageForCharacter(esiClient esi.ESIInterface, characterID int, accessT
|
||||
}
|
||||
logger.Info("GetStorageForCharacter: Pin %d is a storage facility (TypeID: %d)", j+1, pin.TypeID)
|
||||
|
||||
storageType, exists := constants.PI_TYPES_MAP[pin.TypeID]
|
||||
storageType, exists := constants.PITypesMap[pin.TypeID]
|
||||
if !exists {
|
||||
logger.Error("GetStorageForCharacter: Unknown storage type ID %d for planet %s - this should not happen", pin.TypeID, planetNameData.Name)
|
||||
return nil, fmt.Errorf("unknown storage type ID %d", pin.TypeID)
|
||||
|
||||
@@ -150,7 +150,7 @@ func (rh *RouteHandler) handlePlanetDetails(ctx *fasthttp.RequestCtx) {
|
||||
}
|
||||
|
||||
// Fetch planet details using ESI API
|
||||
planetDetail, err := rh.ESI.GetPlanetDetails(context.Background(), int(char.ID), planetID, char.AccessToken)
|
||||
planetDetail, err := rh.ESI.GetPlanetPI(context.Background(), int(char.ID), int64(planetID), char.AccessToken)
|
||||
if err != nil {
|
||||
logger.Error("Failed to fetch planet details for character %s, planet %d: %v", charNameStr, planetID, err)
|
||||
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||
@@ -197,12 +197,12 @@ func (rh *RouteHandler) handlePlanetsFull(ctx *fasthttp.RequestCtx) {
|
||||
// Fetch details for each planet
|
||||
type PlanetWithDetails struct {
|
||||
Planet esi.Planet
|
||||
Details *esi.PlanetDetail
|
||||
Details *esi.PlanetPI
|
||||
}
|
||||
|
||||
var planetsWithDetails []PlanetWithDetails
|
||||
for _, planet := range planets {
|
||||
details, err := rh.ESI.GetPlanetDetails(context.Background(), int(char.ID), planet.PlanetID, char.AccessToken)
|
||||
details, err := rh.ESI.GetPlanetPI(context.Background(), int(char.ID), planet.PlanetID, char.AccessToken)
|
||||
if err != nil {
|
||||
logger.Warning("Failed to fetch details for planet %d: %v", planet.PlanetID, err)
|
||||
// Continue with other planets even if one fails
|
||||
@@ -237,8 +237,21 @@ func (rh *RouteHandler) handleGetExtractors(ctx *fasthttp.RequestCtx) {
|
||||
return
|
||||
}
|
||||
|
||||
planets, err := rh.ESI.GetCharacterPlanets(context.Background(), int(char.ID), char.AccessToken)
|
||||
if err != nil {
|
||||
logger.Error("Failed to get planets for character %s: %v", characterName, err)
|
||||
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||
ctx.SetBodyString("Failed to get planets")
|
||||
return
|
||||
}
|
||||
|
||||
planetIds := make([]int64, len(planets))
|
||||
for i, planet := range planets {
|
||||
planetIds[i] = planet.PlanetID
|
||||
}
|
||||
|
||||
// Get extractors using the standalone function
|
||||
extractors, err := GetExtractorsForCharacter(rh.ESI, int(char.ID), char.AccessToken)
|
||||
extractors, err := GetExtractorsForCharacter(rh.ESI, int(char.ID), char.AccessToken, planetIds)
|
||||
if err != nil {
|
||||
logger.Error("Failed to get extractors for character %s: %v", characterName, err)
|
||||
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
|
||||
|
||||
Reference in New Issue
Block a user