2019-11-14 21:07:19 -08:00
|
|
|
package asynq
|
|
|
|
|
|
2019-12-01 07:59:52 -08:00
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
)
|
2019-11-22 06:16:43 -08:00
|
|
|
|
2019-11-16 14:45:51 -08:00
|
|
|
/*
|
|
|
|
|
TODOs:
|
2019-11-30 09:38:46 -08:00
|
|
|
- [P0] Go docs + CONTRIBUTION.md
|
2019-11-23 16:44:22 -08:00
|
|
|
- [P1] Add Support for multiple queues and priority
|
2019-11-17 15:36:33 -08:00
|
|
|
- [P1] User defined max-retry count
|
|
|
|
|
- [P2] Web UI
|
2019-11-16 14:45:51 -08:00
|
|
|
*/
|
|
|
|
|
|
2019-11-17 13:25:01 -08:00
|
|
|
// Max retry count by default
|
|
|
|
|
const defaultMaxRetry = 25
|
|
|
|
|
|
2019-11-14 21:07:19 -08:00
|
|
|
// Task represents a task to be performed.
|
|
|
|
|
type Task struct {
|
2019-11-16 14:45:51 -08:00
|
|
|
// Type indicates the kind of the task to be performed.
|
|
|
|
|
Type string
|
|
|
|
|
|
|
|
|
|
// Payload is an arbitrary data needed for task execution.
|
|
|
|
|
// The value has to be serializable.
|
|
|
|
|
Payload map[string]interface{}
|
2019-11-14 21:07:19 -08:00
|
|
|
}
|
|
|
|
|
|
2019-11-17 13:25:01 -08:00
|
|
|
// taskMessage is an internal representation of a task with additional metadata fields.
|
|
|
|
|
// This data gets written in redis.
|
|
|
|
|
type taskMessage struct {
|
2019-11-22 06:16:43 -08:00
|
|
|
//-------- Task fields --------
|
|
|
|
|
|
2019-11-17 13:25:01 -08:00
|
|
|
Type string
|
|
|
|
|
Payload map[string]interface{}
|
|
|
|
|
|
2019-11-22 06:16:43 -08:00
|
|
|
//-------- metadata fields --------
|
|
|
|
|
|
|
|
|
|
// unique identifier for each task
|
|
|
|
|
ID uuid.UUID
|
|
|
|
|
|
2019-11-17 13:25:01 -08:00
|
|
|
// queue name this message should be enqueued to
|
2019-11-14 21:07:19 -08:00
|
|
|
Queue string
|
2019-11-17 13:25:01 -08:00
|
|
|
|
2019-11-17 18:44:40 -08:00
|
|
|
// max number of retry for this task.
|
2019-11-17 13:25:01 -08:00
|
|
|
Retry int
|
|
|
|
|
|
|
|
|
|
// number of times we've retried so far
|
|
|
|
|
Retried int
|
|
|
|
|
|
|
|
|
|
// error message from the last failure
|
|
|
|
|
ErrorMsg string
|
2019-11-14 21:07:19 -08:00
|
|
|
}
|
|
|
|
|
|
2019-12-03 19:43:01 -08:00
|
|
|
// RedisConfig specifies redis configurations.
|
|
|
|
|
type RedisConfig struct {
|
2019-11-14 21:07:19 -08:00
|
|
|
Addr string
|
|
|
|
|
Password string
|
2019-11-24 18:41:55 -08:00
|
|
|
|
|
|
|
|
// DB specifies which redis database to select.
|
|
|
|
|
DB int
|
2019-11-14 21:07:19 -08:00
|
|
|
}
|
2019-12-01 07:59:52 -08:00
|
|
|
|
|
|
|
|
// Stats represents a state of queues at a certain time.
|
|
|
|
|
type Stats struct {
|
|
|
|
|
Queued int
|
|
|
|
|
InProgress int
|
|
|
|
|
Scheduled int
|
|
|
|
|
Retry int
|
|
|
|
|
Dead int
|
|
|
|
|
Timestamp time.Time
|
|
|
|
|
}
|