Make Task type immutable

This change makes it impossible to mutate payload within Handler or
RetryDelayFunc.
This commit is contained in:
Ken Hibino
2020-01-04 13:13:46 -08:00
parent 899566e661
commit f3a23b9b12
14 changed files with 92 additions and 345 deletions

View File

@@ -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},
}
}