-
Notifications
You must be signed in to change notification settings - Fork 126
/
taskqueue.go
60 lines (44 loc) · 1.37 KB
/
taskqueue.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
51
52
53
54
55
56
57
58
59
60
package taskqueue
import (
"context"
"github.com/hatchet-dev/hatchet/internal/repository/prisma/db"
)
type QueueType string
const (
EVENT_PROCESSING_QUEUE QueueType = "event_processing_queue"
JOB_PROCESSING_QUEUE QueueType = "job_processing_queue"
DISPATCHER_POOL_QUEUE QueueType = "dispatcher_pool_queue"
SCHEDULING_QUEUE QueueType = "scheduling_queue"
)
func QueueTypeFromDispatcher(d *db.DispatcherModel) QueueType {
if d == nil {
return ""
}
return QueueType(d.ID)
}
func QueueTypeFromTicker(t *db.TickerModel) QueueType {
if t == nil {
return ""
}
return QueueType(t.ID)
}
type Task struct {
// ID is the ID of the task.
ID string `json:"id"`
// Queue is the queue of the task.
Queue QueueType `json:"queue"`
// Payload is the payload of the task.
Payload map[string]interface{} `json:"payload"`
// Metadata is the metadata of the task.
Metadata map[string]interface{} `json:"metadata"`
// Retries is the number of retries for the task.
Retries int `json:"retries"`
// RetryDelay is the delay between retries.
RetryDelay int `json:"retry_delay"`
}
type TaskQueue interface {
// AddTask adds a task to the queue. Implementations should ensure that Start().
AddTask(ctx context.Context, queue QueueType, task *Task) error
// Subscribe subscribes to the task queue.
Subscribe(ctx context.Context, queueType QueueType) (<-chan *Task, error)
}