-
Notifications
You must be signed in to change notification settings - Fork 68
feat: implement persistent job queue with bbolt and maintenance worker #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
its-me-abhishek marked this conversation as resolved.
Show resolved
Hide resolved
|
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added required dependencies for bbolt and cron |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module ccsync_backend | ||
|
|
||
| go 1.19 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can this be skipped?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Go 1.23 bump is because bbolt v1.4.3 requires it. I can either downgrade bbolt to v1.3.7 (works with Go 1.19) or keep 1.23. Leaning towards downgrading to stay consistent with the codebase. any Thoughts? |
||
| go 1.23 | ||
|
|
||
| require ( | ||
| github.com/charmbracelet/log v0.4.2 | ||
|
|
@@ -33,8 +33,10 @@ require ( | |
| github.com/muesli/termenv v0.16.0 // indirect | ||
| github.com/pmezard/go-difflib v1.0.0 // indirect | ||
| github.com/rivo/uniseg v0.4.7 // indirect | ||
| github.com/robfig/cron/v3 v3.0.1 // indirect | ||
| github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect | ||
| github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect | ||
| go.etcd.io/bbolt v1.4.3 // indirect | ||
| golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect | ||
| golang.org/x/net v0.17.0 // indirect | ||
| golang.org/x/sys v0.30.0 // indirect | ||
|
|
||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added required dependencies for bbolt and cron |
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. initialize maintenance worker on startup, clean integration |
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implemented simple cron worker for cleeanup,configurable schedule and retention |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package utils | ||
|
|
||
| import ( | ||
| "os" | ||
| "strconv" | ||
|
|
||
| "github.com/robfig/cron/v3" | ||
| ) | ||
|
|
||
| type MaintenanceWorker struct { | ||
| cron *cron.Cron | ||
| queue PersistentJobQueue | ||
| } | ||
|
|
||
| func NewMaintenanceWorker(queue PersistentJobQueue) *MaintenanceWorker { | ||
| return &MaintenanceWorker{ | ||
| cron: cron.New(), | ||
| queue: queue, | ||
| } | ||
| } | ||
|
|
||
| func (mw *MaintenanceWorker) Start() error { | ||
| schedule := os.Getenv("CLEANUP_CRON_SCHEDULE") | ||
| if schedule == "" { | ||
| schedule = "0 0 * * *" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe provide some more context on these in form of comments and how to update it as well. what can be the other values for this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure , Added detailed comments explaining the cron format and example values. will push changes soon when complete change ready ! |
||
| } | ||
|
|
||
| retentionDaysStr := os.Getenv("CLEANUP_RETENTION_DAYS") | ||
| retentionDays := 7 | ||
| if retentionDaysStr != "" { | ||
| if days, err := strconv.Atoi(retentionDaysStr); err == nil { | ||
| retentionDays = days | ||
| } | ||
| } | ||
|
|
||
| _, err := mw.cron.AddFunc(schedule, func() { | ||
| Logger.Infof("Starting job cleanup, retention: %d days", retentionDays) | ||
| if err := mw.queue.CleanupOldJobs(retentionDays); err != nil { | ||
| Logger.Errorf("Failed to cleanup old jobs: %v", err) | ||
| } else { | ||
| Logger.Infof("Job cleanup completed successfully") | ||
| } | ||
| }) | ||
|
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| mw.cron.Start() | ||
| Logger.Infof("Maintenance worker started with schedule: %s", schedule) | ||
| return nil | ||
| } | ||
|
|
||
| func (mw *MaintenanceWorker) Stop() { | ||
| mw.cron.Stop() | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documented new config options and persistent queue feature