From 4e4a8729f3c5b0ce5ccd6635e2ac42fef5b1c056 Mon Sep 17 00:00:00 2001 From: hossein varmazyar Date: Sat, 1 Aug 2020 18:57:34 +0430 Subject: [PATCH 1/2] add job arguments to periodic jobs --- go.mod | 2 -- periodic_enqueuer.go | 3 ++- worker_pool.go | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 224eab98..33ae2b26 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,6 @@ require ( github.com/garyburd/redigo v1.6.0 // indirect github.com/gocraft/health v0.0.0-20170925182251-8675af27fef0 github.com/gocraft/web v0.0.0-20190207150652-9707327fb69b - github.com/gocraft/work v0.5.1 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect github.com/gomodule/redigo v2.0.0+incompatible github.com/jrallison/go-workers v0.0.0-20180112190529-dbf81d0b75bb @@ -24,6 +23,5 @@ require ( github.com/robfig/cron v1.2.0 // indirect github.com/robfig/cron/v3 v3.0.1 github.com/stretchr/testify v1.5.1 - github.com/youtube/vitess v2.1.1+incompatible // indirect golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect ) diff --git a/periodic_enqueuer.go b/periodic_enqueuer.go index ae957e7f..425bbaf2 100644 --- a/periodic_enqueuer.go +++ b/periodic_enqueuer.go @@ -27,6 +27,7 @@ type periodicJob struct { jobName string spec string schedule cron.Schedule + args map[string]interface{} } type scheduledPeriodicJob struct { @@ -102,7 +103,7 @@ func (pe *periodicEnqueuer) enqueue() error { // This is technically wrong, but this lets the bytes be identical for the same periodic job instance. If we don't do this, we'd need to use a different approach -- probably giving each periodic job its own history of the past 100 periodic jobs, and only scheduling a job if it's not in the history. EnqueuedAt: epoch, - Args: nil, + Args: pj.args, } rawJSON, err := job.serialize() diff --git a/worker_pool.go b/worker_pool.go index d83c7b79..56ebc4be 100644 --- a/worker_pool.go +++ b/worker_pool.go @@ -1,13 +1,13 @@ package work import ( + "github.com/robfig/cron/v3" "reflect" "sort" "strings" "sync" "github.com/gomodule/redigo/redis" - "github.com/robfig/cron/v3" ) // WorkerPool represents a pool of workers. It forms the primary API of gocraft/work. WorkerPools provide the public API of gocraft/work. You can attach jobs and middlware to them. You can start and stop them. Based on their concurrency setting, they'll spin up N worker goroutines. @@ -179,7 +179,7 @@ func (wp *WorkerPool) JobWithOptions(name string, jobOpts JobOptions, fn interfa // The spec format is based on https://godoc.org/github.com/robfig/cron, which is a relatively standard cron format. // Note that the first value is the seconds! // If you have multiple worker pools on different machines, they'll all coordinate and only enqueue your job once. -func (wp *WorkerPool) PeriodicallyEnqueue(spec string, jobName string) *WorkerPool { +func (wp *WorkerPool) PeriodicallyEnqueue(spec string, jobName string, jobArgs map[string]interface{}) *WorkerPool { p := cron.NewParser(cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor) schedule, err := p.Parse(spec) @@ -187,7 +187,7 @@ func (wp *WorkerPool) PeriodicallyEnqueue(spec string, jobName string) *WorkerPo panic(err) } - wp.periodicJobs = append(wp.periodicJobs, &periodicJob{jobName: jobName, spec: spec, schedule: schedule}) + wp.periodicJobs = append(wp.periodicJobs, &periodicJob{jobName: jobName, spec: spec, schedule: schedule, args: jobArgs}) return wp } From 32b4be383657dd437372cdef98f2389ff86167fe Mon Sep 17 00:00:00 2001 From: hossein varmazyar Date: Sat, 8 Aug 2020 21:29:07 +0430 Subject: [PATCH 2/2] change go mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 33ae2b26..1c65abf5 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/gocraft/work +module github.com/mrNobody95/redisGoWork go 1.14