diff options
Diffstat (limited to 'plugins/jobs/structs')
-rw-r--r-- | plugins/jobs/structs/general.go | 19 | ||||
-rw-r--r-- | plugins/jobs/structs/job.go | 51 | ||||
-rw-r--r-- | plugins/jobs/structs/job_options.go | 5 | ||||
-rw-r--r-- | plugins/jobs/structs/job_test.go | 20 |
4 files changed, 20 insertions, 75 deletions
diff --git a/plugins/jobs/structs/general.go b/plugins/jobs/structs/general.go new file mode 100644 index 00000000..ae754286 --- /dev/null +++ b/plugins/jobs/structs/general.go @@ -0,0 +1,19 @@ +package structs + +// Job carries information about single job. +type Job struct { + // Job contains name of job broker (usually PHP class). + Job string `json:"job"` + + // Ident is unique identifier of the job, should be provided from outside + Ident string + + // Payload is string data (usually JSON) passed to Job broker. + Payload string `json:"payload"` + + // Headers with key-value pairs + Headers map[string][]string + + // Options contains set of PipelineOptions specific to job execution. Can be empty. + Options *Options `json:"options,omitempty"` +} diff --git a/plugins/jobs/structs/job.go b/plugins/jobs/structs/job.go deleted file mode 100644 index 1ef4d2ca..00000000 --- a/plugins/jobs/structs/job.go +++ /dev/null @@ -1,51 +0,0 @@ -package structs - -import ( - json "github.com/json-iterator/go" - "github.com/spiral/roadrunner/v2/utils" -) - -// Job carries information about single job. -type Job struct { - // Job contains name of job broker (usually PHP class). - Job string `json:"job"` - - // Payload is string data (usually JSON) passed to Job broker. - Payload string `json:"payload"` - - // Options contains set of PipelineOptions specific to job execution. Can be empty. - 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() []byte { - ctx, _ := json.Marshal( - struct { - ID *string `json:"id"` - Job string `json:"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 3e1ada85..d48e2c56 100644 --- a/plugins/jobs/structs/job_options.go +++ b/plugins/jobs/structs/job_options.go @@ -6,10 +6,7 @@ import "time" 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"` + Priority uint64 `json:"priority"` // 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 deleted file mode 100644 index 0aa5b177..00000000 --- a/plugins/jobs/structs/job_test.go +++ /dev/null @@ -1,20 +0,0 @@ -package structs - -import ( - "testing" - - "github.com/spiral/roadrunner/v2/utils" - "github.com/stretchr/testify/assert" -) - -func TestJob_Body(t *testing.T) { - j := &Job{Payload: "hello"} - - assert.Equal(t, []byte("hello"), j.Body()) -} - -func TestJob_Context(t *testing.T) { - j := &Job{Job: "job", Options: &Options{ID: utils.AsStringPtr("id")}} - - assert.Equal(t, []byte(`{"id":"id","job":"job"}`), j.Context()) -} |