Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove old finished jobs from status map to avoid leaks
  • Loading branch information
owen-d committed Dec 10, 2024
commit 2608b00482fe9451c0217f844a9e5997cda79ee8
13 changes: 8 additions & 5 deletions pkg/blockbuilder/scheduler/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const (
// JobWithMetadata wraps a job with additional metadata for tracking its lifecycle
type JobWithMetadata struct {
*types.Job
Priority int
Status types.JobStatus
StartTime time.Time
UpdateTime time.Time
Priority int
Status types.JobStatus
StartTime time.Time
UpdateTime time.Time
}

// NewJobWithMetadata creates a new JobWithMetadata instance
Expand Down Expand Up @@ -135,7 +135,10 @@ func (q *JobQueue) MarkComplete(id string, status types.JobStatus) {
jobMeta.UpdateTime = time.Now()

// Add to completed buffer
_, _ = q.completed.Push(jobMeta)
if old, evicted := q.completed.Push(jobMeta); evicted {
// If the buffer is full, evict the oldest job and remove it from the status map to avoid leaks
delete(q.statusMap, old.ID)
}

// Update status map and clean up
q.statusMap[id] = status
Expand Down