-
Notifications
You must be signed in to change notification settings - Fork 2
/
state.go
50 lines (44 loc) · 1.72 KB
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package queue
import "github.com/hibiken/asynq"
// JobState represents the state of a job in the queue.
type JobState string
const (
// StateActive represents jobs that are currently being processed.
StateActive JobState = "active"
// StatePending represents jobs that are waiting to be processed.
StatePending JobState = "pending"
// StateRetry represents jobs that will be retried after a failure.
StateRetry JobState = "retry"
// StateArchived represents jobs that have been moved to the archive.
StateArchived JobState = "archived"
// StateCompleted represents jobs that have been completed successfully.
StateCompleted JobState = "completed"
// StateScheduled represents jobs that are scheduled to be run in the future.
StateScheduled JobState = "scheduled"
// StateAggregating represents jobs that are part of a batch or group waiting to be processed together.
StateAggregating JobState = "aggregating"
)
// IsValidJobState checks if the provided job state is valid and supported.
func IsValidJobState(state JobState) bool {
switch state {
case StateActive, StatePending, StateRetry, StateArchived, StateCompleted, StateScheduled, StateAggregating:
return true
default:
return false
}
}
var taskStateToJobStateMap = map[asynq.TaskState]JobState{
asynq.TaskStateActive: StateActive,
asynq.TaskStatePending: StatePending,
asynq.TaskStateScheduled: StateScheduled,
asynq.TaskStateRetry: StateRetry,
asynq.TaskStateArchived: StateArchived,
asynq.TaskStateCompleted: StateCompleted,
asynq.TaskStateAggregating: StateAggregating,
}
func toJobState(taskState asynq.TaskState) JobState {
if jobState, exists := taskStateToJobStateMap[taskState]; exists {
return jobState
}
return JobState("unknown")
}