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

Commit

Permalink
reset counter
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio1988 committed Sep 13, 2023
1 parent ffd24a0 commit 754fb75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions routes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func handleGetJob(c *gin.Context, req ControllerBody, workerState *worker.State)
if !isValid || workerState.Username != req.Username {
log.Debugf("[CONTROLLER] [%s] Account '%s' is not valid.", req.Uuid, req.Username)
workerState.ResetUsername()
workerState.ResetCounter()
respondWithData(c, &map[string]any{
"action": SwitchAccount.String(),
"min_level": 30,
Expand Down
8 changes: 8 additions & 0 deletions worker/requestCounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ func (r *RequestCounter) RequestCounts() map[int]int {
return countsCopy
}

func (r *RequestCounter) ResetCounts() {
r.mutex.Lock()
defer r.mutex.Unlock()
for k, _ := range r.counts {
r.counts[k] = 0
}
}

func (r *RequestCounter) SetLimits(limits map[int]int) {
r.limits = limits
}
Expand Down
4 changes: 4 additions & 0 deletions worker/workerState.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,7 @@ func (ws *State) CheckLimitExceeded() bool {
func (ws *State) RequestCounts() map[int]int {
return ws.requestCounter.RequestCounts()
}

func (ws *State) ResetCounter() {
ws.requestCounter.ResetCounts()
}

0 comments on commit 754fb75

Please sign in to comment.