Added task worker service and example task processor.
This commit is contained in:
parent
726556e973
commit
83cdbc4395
6 changed files with 105 additions and 13 deletions
|
|
@ -22,7 +22,7 @@ type (
|
|||
// task handles task creation operations
|
||||
task struct {
|
||||
client *TaskClient
|
||||
name string
|
||||
typ string
|
||||
payload interface{}
|
||||
periodic *string
|
||||
queue *string
|
||||
|
|
@ -67,10 +67,10 @@ func (t *TaskClient) StartScheduler() error {
|
|||
}
|
||||
|
||||
// New starts a task creation operation
|
||||
func (t *TaskClient) New(name string) *task {
|
||||
func (t *TaskClient) New(typ string) *task {
|
||||
return &task{
|
||||
client: t,
|
||||
name: name,
|
||||
typ: typ,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +167,7 @@ func (t *task) Save() error {
|
|||
}
|
||||
|
||||
// Build the task
|
||||
task := asynq.NewTask(t.name, payload, opts...)
|
||||
task := asynq.NewTask(t.typ, payload, opts...)
|
||||
|
||||
// Schedule, if needed
|
||||
if t.periodic != nil {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ func TestTaskClient_New(t *testing.T) {
|
|||
Wait(6 * time.Second).
|
||||
Retain(7 * time.Second)
|
||||
|
||||
assert.Equal(t, "task1", tk.name)
|
||||
assert.Equal(t, "task1", tk.typ)
|
||||
assert.Equal(t, "payload", tk.payload.(string))
|
||||
assert.Equal(t, "queue", *tk.queue)
|
||||
assert.Equal(t, "@every 5s", *tk.periodic)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue