Skip to content

Commit

Permalink
fix: start job history channel fetch before adding items
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Sep 22, 2024
1 parent 9848b00 commit 1ddb448
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 15 additions & 1 deletion job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,21 @@ const (
maxJitterDuration = time.Minute * 15
)

var EvictedJobs chan uuid.UUID
var (
EvictedJobs chan uuid.UUID
startedJobHistory = false
)

func StartJobHistoryEvictor(ctx context.Context) {
if !startedJobHistory {
if EvictedJobs == nil {
EvictedJobs = make(chan uuid.UUID, 1000)
}
go deleteEvictedJobs(ctx)
startedJobHistory = true
}

}

// deleteEvictedJobs deletes job_history rows from the DB every job.eviction.period(1m),
// jobs send rows to be deleted by maintaining a circular buffer by status type
Expand Down
2 changes: 2 additions & 0 deletions upstream/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/flanksource/commons/logger"
"github.com/flanksource/duty/api"
"github.com/flanksource/duty/context"
"github.com/flanksource/duty/job"
"github.com/flanksource/duty/models"
"github.com/labstack/echo/v4"
"github.com/patrickmn/go-cache"
Expand Down Expand Up @@ -112,6 +113,7 @@ func addJobHistoryToRing(ctx context.Context, agentID string, histories []models
if ringManager == nil {
return
}
job.StartJobHistoryEvictor(ctx)

for _, history := range histories {
ringManager.Add(ctx, agentID, history)
Expand Down

0 comments on commit 1ddb448

Please sign in to comment.