Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

fix: unbound #19

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions routes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"flygon/worker"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"math"
"net/http"
"strconv"
"sync"
Expand Down Expand Up @@ -197,6 +198,18 @@ func handleGetJob(c *gin.Context, req ControllerBody, workerState *worker.State)
return
}

if workerState.AreaId == math.MaxInt {
task := map[string]any{
"action": ScanPokemon.String(),
"lat": 0.0,
"lon": 0.0,
"min_level": 30,
"max_level": 40,
}
respondWithData(c, &task)
return
}

wa := worker.GetWorkerArea(workerState.AreaId)
if wa == nil {
log.Debugf("[CONTROLLER] [%s] Area '%d' does not exist", req.Uuid, workerState.AreaId)
Expand Down
13 changes: 13 additions & 0 deletions worker/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package worker

import (
"math"
"os"
// "time"

Expand Down Expand Up @@ -54,6 +55,18 @@ func StartAreas(dbDetails db.DbDetails) {

//go workerArea.Start()
}
// register unbound area
RegisterArea(&WorkerArea{
Id: math.MaxInt,
Name: "unbound",
TargetWorkerCount: 0,
route: nil,
pokemonRoute: nil,
questFence: geo.Geofence{},
questRoute: nil,
questCheckHours: nil,
questCheckLastHour: -1,
})

// come back when quests are ready
// if config.Config.Koji.Url != "" {
Expand Down
6 changes: 6 additions & 0 deletions worker/workerarea.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"flygon/koji"
"github.com/jellydator/ttlcache/v3"
log "github.com/sirupsen/logrus"
"math"
"strings"
"sync"
"time"
)
Expand Down Expand Up @@ -154,6 +156,10 @@ func (ws *State) AllocateArea() (*WorkerArea, error) {
if ws.AreaId != 0 { // no area uses ID = 0, auto increment starts with 1
return workerAreas[ws.AreaId], nil
}
if strings.HasSuffix(ws.Uuid, "_enc") {
ws.AreaId = math.MaxInt
return workerAreas[math.MaxInt], nil
}
// Find area with the least workers
// Add worker to area
// Set states
Expand Down