summaryrefslogtreecommitdiff
path: root/plugins/jobs/structs
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jobs/structs')
-rw-r--r--plugins/jobs/structs/job.go10
-rw-r--r--plugins/jobs/structs/job_options.go12
-rw-r--r--plugins/jobs/structs/job_options_test.go16
-rw-r--r--plugins/jobs/structs/job_test.go3
4 files changed, 21 insertions, 20 deletions
diff --git a/plugins/jobs/structs/job.go b/plugins/jobs/structs/job.go
index 268444db..1ef4d2ca 100644
--- a/plugins/jobs/structs/job.go
+++ b/plugins/jobs/structs/job.go
@@ -17,12 +17,12 @@ type Job struct {
Options *Options `json:"options,omitempty"`
}
-func (j *Job) ID() string {
+func (j *Job) ID() *string {
return j.Options.ID
}
-func (j *Job) Priority() uint64 {
- return *j.Options.Priority
+func (j *Job) Priority() *uint64 {
+ return j.Options.Priority
}
// Body packs job payload into binary payload.
@@ -34,8 +34,8 @@ func (j *Job) Body() []byte {
func (j *Job) Context() []byte {
ctx, _ := json.Marshal(
struct {
- ID string `json:"id"`
- Job string `json:"job"`
+ ID *string `json:"id"`
+ Job string `json:"job"`
}{ID: j.Options.ID, Job: j.Job},
)
diff --git a/plugins/jobs/structs/job_options.go b/plugins/jobs/structs/job_options.go
index 029a797d..3e1ada85 100644
--- a/plugins/jobs/structs/job_options.go
+++ b/plugins/jobs/structs/job_options.go
@@ -9,23 +9,23 @@ type Options struct {
Priority *uint64 `json:"priority"`
// ID - generated ID for the job
- ID string `json:"id"`
+ ID *string `json:"id"`
// Pipeline manually specified pipeline.
Pipeline string `json:"pipeline,omitempty"`
// Delay defines time duration to delay execution for. Defaults to none.
- Delay int `json:"delay,omitempty"`
+ Delay uint64 `json:"delay,omitempty"`
// Attempts define maximum job retries. Attention, value 1 will only allow job to execute once (without retry).
// Minimum valuable value is 2.
- Attempts int `json:"maxAttempts,omitempty"`
+ Attempts uint64 `json:"maxAttempts,omitempty"`
// RetryDelay defines for how long job should be waiting until next retry. Defaults to none.
- RetryDelay int `json:"retryDelay,omitempty"`
+ RetryDelay uint64 `json:"retryDelay,omitempty"`
// Reserve defines for how broker should wait until treating job are failed. Defaults to 30 min.
- Timeout int `json:"timeout,omitempty"`
+ Timeout uint64 `json:"timeout,omitempty"`
}
// Merge merges job options.
@@ -52,7 +52,7 @@ func (o *Options) Merge(from *Options) {
}
// CanRetry must return true if broker is allowed to re-run the job.
-func (o *Options) CanRetry(attempt int) bool {
+func (o *Options) CanRetry(attempt uint64) bool {
// Attempts 1 and 0 has identical effect
return o.Attempts > (attempt + 1)
}
diff --git a/plugins/jobs/structs/job_options_test.go b/plugins/jobs/structs/job_options_test.go
index 18702394..a16f7dd0 100644
--- a/plugins/jobs/structs/job_options_test.go
+++ b/plugins/jobs/structs/job_options_test.go
@@ -79,10 +79,10 @@ func TestOptions_Merge(t *testing.T) {
})
assert.Equal(t, "pipeline", opts.Pipeline)
- assert.Equal(t, 1, opts.Attempts)
- assert.Equal(t, 2, opts.Delay)
- assert.Equal(t, 1, opts.Timeout)
- assert.Equal(t, 1, opts.RetryDelay)
+ assert.Equal(t, uint64(1), opts.Attempts)
+ assert.Equal(t, uint64(2), opts.Delay)
+ assert.Equal(t, uint64(1), opts.Timeout)
+ assert.Equal(t, uint64(1), opts.RetryDelay)
}
func TestOptions_MergeKeepOriginal(t *testing.T) {
@@ -103,8 +103,8 @@ func TestOptions_MergeKeepOriginal(t *testing.T) {
})
assert.Equal(t, "default", opts.Pipeline)
- assert.Equal(t, 10, opts.Attempts)
- assert.Equal(t, 10, opts.Delay)
- assert.Equal(t, 10, opts.Timeout)
- assert.Equal(t, 10, opts.RetryDelay)
+ assert.Equal(t, uint64(10), opts.Attempts)
+ assert.Equal(t, uint64(10), opts.Delay)
+ assert.Equal(t, uint64(10), opts.Timeout)
+ assert.Equal(t, uint64(10), opts.RetryDelay)
}
diff --git a/plugins/jobs/structs/job_test.go b/plugins/jobs/structs/job_test.go
index 92f78081..0aa5b177 100644
--- a/plugins/jobs/structs/job_test.go
+++ b/plugins/jobs/structs/job_test.go
@@ -3,6 +3,7 @@ package structs
import (
"testing"
+ "github.com/spiral/roadrunner/v2/utils"
"github.com/stretchr/testify/assert"
)
@@ -13,7 +14,7 @@ func TestJob_Body(t *testing.T) {
}
func TestJob_Context(t *testing.T) {
- j := &Job{Job: "job", Options: &Options{ID: "id"}}
+ j := &Job{Job: "job", Options: &Options{ID: utils.AsStringPtr("id")}}
assert.Equal(t, []byte(`{"id":"id","job":"job"}`), j.Context())
}