mirror of
https://github.com/hibiken/asynq.git
synced 2025-09-19 05:17:30 +08:00
Make Task type immutable
This change makes it impossible to mutate payload within Handler or RetryDelayFunc.
This commit is contained in:
13
asynq.go
13
asynq.go
@@ -11,9 +11,20 @@ TODOs:
|
||||
|
||||
// Task represents a task to be performed.
|
||||
type Task struct {
|
||||
// Type indicates the kind of the task to be performed.
|
||||
// Type indicates the type of task to be performed.
|
||||
Type string
|
||||
|
||||
// Payload holds data needed to process the task.
|
||||
Payload Payload
|
||||
}
|
||||
|
||||
// NewTask returns a new instance of a task given a task type and payload.
|
||||
//
|
||||
// Since payload data gets serialized to JSON, the payload values must be
|
||||
// composed of JSON supported data types.
|
||||
func NewTask(typename string, payload map[string]interface{}) *Task {
|
||||
return &Task{
|
||||
Type: typename,
|
||||
Payload: Payload{payload},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user