2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-09-20 11:05:58 +08:00
asynq/asynq.go

122 lines
2.7 KiB
Go
Raw Normal View History

2019-11-15 13:07:19 +08:00
package asynq
2019-12-01 23:59:52 +08:00
import (
"time"
"github.com/google/uuid"
)
2019-11-22 22:16:43 +08:00
2019-11-17 06:45:51 +08:00
/*
TODOs:
2019-12-01 01:38:46 +08:00
- [P0] Go docs + CONTRIBUTION.md
2019-11-24 08:44:22 +08:00
- [P1] Add Support for multiple queues and priority
2019-11-18 07:36:33 +08:00
- [P1] User defined max-retry count
- [P2] Web UI
2019-11-17 06:45:51 +08:00
*/
// Max retry count by default
const defaultMaxRetry = 25
2019-11-15 13:07:19 +08:00
// Task represents a task to be performed.
type Task struct {
2019-11-17 06: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-15 13:07:19 +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 22:16:43 +08:00
//-------- Task fields --------
Type string
Payload map[string]interface{}
2019-11-22 22:16:43 +08:00
//-------- metadata fields --------
// unique identifier for each task
ID uuid.UUID
// queue name this message should be enqueued to
2019-11-15 13:07:19 +08:00
Queue string
2019-11-18 10:44:40 +08:00
// max number of retry for this task.
Retry int
// number of times we've retried so far
Retried int
// error message from the last failure
ErrorMsg string
2019-11-15 13:07:19 +08:00
}
2019-12-04 11:43:01 +08:00
// RedisConfig specifies redis configurations.
type RedisConfig struct {
2019-11-15 13:07:19 +08:00
Addr string
Password string
// DB specifies which redis database to select.
DB int
2019-11-15 13:07:19 +08:00
}
2019-12-01 23: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
}
2019-12-02 22:55:04 +08:00
// EnqueuedTask is a task in a queue and is ready to be processed.
// This is read only and used for inspection purpose.
type EnqueuedTask struct {
ID uuid.UUID
Type string
Payload map[string]interface{}
}
// InProgressTask is a task that's currently being processed.
// This is read only and used for inspection purpose.
type InProgressTask struct {
ID uuid.UUID
Type string
Payload map[string]interface{}
}
// ScheduledTask is a task that's scheduled to be processed in the future.
// This is read only and used for inspection purpose.
type ScheduledTask struct {
ID uuid.UUID
Type string
Payload map[string]interface{}
ProcessAt time.Time
}
// RetryTask is a task that's in retry queue because worker failed to process the task.
// This is read only and used for inspection purpose.
type RetryTask struct {
ID uuid.UUID
Type string
Payload map[string]interface{}
// TODO(hibiken): add LastFailedAt time.Time
ProcessAt time.Time
2019-12-02 22:55:04 +08:00
ErrorMsg string
Retried int
Retry int
2019-12-02 22:55:04 +08:00
}
// DeadTask is a task in that has exhausted all retries.
// This is read only and used for inspection purpose.
type DeadTask struct {
ID uuid.UUID
Type string
Payload map[string]interface{}
LastFailedAt time.Time
ErrorMsg string
2019-12-02 22:55:04 +08:00
}