2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-26 07:42:17 +08:00

Change TaskMessage Timeout and Deadline to int

* This change breaks existing tasks in Redis
This commit is contained in:
Ken Hibino 2020-06-16 21:11:54 -07:00
parent 5dddc35d7c
commit 0527b93432
3 changed files with 34 additions and 28 deletions

View File

@ -75,11 +75,13 @@ var IgnoreIDOpt = cmpopts.IgnoreFields(base.TaskMessage{}, "ID")
// NewTaskMessage returns a new instance of TaskMessage given a task type and payload. // NewTaskMessage returns a new instance of TaskMessage given a task type and payload.
func NewTaskMessage(taskType string, payload map[string]interface{}) *base.TaskMessage { func NewTaskMessage(taskType string, payload map[string]interface{}) *base.TaskMessage {
return &base.TaskMessage{ return &base.TaskMessage{
ID: xid.New(), ID: xid.New(),
Type: taskType, Type: taskType,
Queue: base.DefaultQueueName, Queue: base.DefaultQueueName,
Retry: 25, Retry: 25,
Payload: payload, Payload: payload,
Timeout: 1800, // default timeout of 30 mins
Deadline: 0, // no deadline
} }
} }

View File

@ -89,18 +89,20 @@ type TaskMessage struct {
// ErrorMsg holds the error message from the last failure. // ErrorMsg holds the error message from the last failure.
ErrorMsg string ErrorMsg string
// Timeout specifies how long a task may run. // Timeout specifies timeout in seconds.
// The string value should be compatible with time.Duration.ParseDuration. // If task processing doesn't complete within the timeout, the task will be retried
// if retry count is remaining. Otherwise it will be moved to the dead queue.
// //
// Zero means no limit. // Use zero to indicate no timeout.
Timeout string Timeout int
// Deadline specifies the deadline for the task. // Deadline specifies the deadline for the task in Unix time,
// Task won't be processed if it exceeded its deadline. // the number of seconds elapsed since January 1, 1970 UTC.
// The string shoulbe be in RFC3339 format. // If task processing doesn't complete before the deadline, the task will be retried
// if retry count is remaining. Otherwise it will be moved to the dead queue.
// //
// time.Time's zero value means no deadline. // Use zero to indicate no deadline.
Deadline string Deadline int
// UniqueKey holds the redis key used for uniqueness lock for this task. // UniqueKey holds the redis key used for uniqueness lock for this task.
// //

View File

@ -115,22 +115,24 @@ func TestMessageEncoding(t *testing.T) {
}{ }{
{ {
in: &TaskMessage{ in: &TaskMessage{
Type: "task1", Type: "task1",
Payload: map[string]interface{}{"a": 1, "b": "hello!", "c": true}, Payload: map[string]interface{}{"a": 1, "b": "hello!", "c": true},
ID: id, ID: id,
Queue: "default", Queue: "default",
Retry: 10, Retry: 10,
Retried: 0, Retried: 0,
Timeout: "0", Timeout: 1800,
Deadline: 1692311100,
}, },
out: &TaskMessage{ out: &TaskMessage{
Type: "task1", Type: "task1",
Payload: map[string]interface{}{"a": json.Number("1"), "b": "hello!", "c": true}, Payload: map[string]interface{}{"a": json.Number("1"), "b": "hello!", "c": true},
ID: id, ID: id,
Queue: "default", Queue: "default",
Retry: 10, Retry: 10,
Retried: 0, Retried: 0,
Timeout: "0", Timeout: 1800,
Deadline: 1692311100,
}, },
}, },
} }