diff options
Diffstat (limited to 'plugins/jobs/structs')
-rw-r--r-- | plugins/jobs/structs/job.go | 20 | ||||
-rw-r--r-- | plugins/jobs/structs/job_options.go | 7 | ||||
-rw-r--r-- | plugins/jobs/structs/job_test.go | 4 |
3 files changed, 27 insertions, 4 deletions
diff --git a/plugins/jobs/structs/job.go b/plugins/jobs/structs/job.go index 2e394543..268444db 100644 --- a/plugins/jobs/structs/job.go +++ b/plugins/jobs/structs/job.go @@ -17,19 +17,35 @@ type Job struct { Options *Options `json:"options,omitempty"` } +func (j *Job) ID() string { + return j.Options.ID +} + +func (j *Job) Priority() uint64 { + return *j.Options.Priority +} + // Body packs job payload into binary payload. func (j *Job) Body() []byte { return utils.AsBytes(j.Payload) } // Context packs job context (job, id) into binary payload. -func (j *Job) Context(id string) []byte { +func (j *Job) Context() []byte { ctx, _ := json.Marshal( struct { ID string `json:"id"` Job string `json:"job"` - }{ID: id, Job: j.Job}, + }{ID: j.Options.ID, Job: j.Job}, ) return ctx } + +func (j *Job) Ack() { + +} + +func (j *Job) Nack() { + +} diff --git a/plugins/jobs/structs/job_options.go b/plugins/jobs/structs/job_options.go index 1507d053..029a797d 100644 --- a/plugins/jobs/structs/job_options.go +++ b/plugins/jobs/structs/job_options.go @@ -4,6 +4,13 @@ import "time" // Options carry information about how to handle given job. type Options struct { + // Priority is job priority, default - 10 + // pointer to distinguish 0 as a priority and nil as priority not set + Priority *uint64 `json:"priority"` + + // ID - generated ID for the job + ID string `json:"id"` + // Pipeline manually specified pipeline. Pipeline string `json:"pipeline,omitempty"` diff --git a/plugins/jobs/structs/job_test.go b/plugins/jobs/structs/job_test.go index e7240c6b..92f78081 100644 --- a/plugins/jobs/structs/job_test.go +++ b/plugins/jobs/structs/job_test.go @@ -13,7 +13,7 @@ func TestJob_Body(t *testing.T) { } func TestJob_Context(t *testing.T) { - j := &Job{Job: "job"} + j := &Job{Job: "job", Options: &Options{ID: "id"}} - assert.Equal(t, []byte(`{"id":"id","job":"job"}`), j.Context("id")) + assert.Equal(t, []byte(`{"id":"id","job":"job"}`), j.Context()) } |