-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.go
More file actions
43 lines (34 loc) · 1.08 KB
/
options.go
File metadata and controls
43 lines (34 loc) · 1.08 KB
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
package pgqueue
import (
"log/slog"
"time"
)
// QueueOption configures a Queue.
type QueueOption func(*queueConfig)
type queueConfig struct {
logger *slog.Logger
}
// WithLogger sets the logger for the Queue and its Workers.
func WithLogger(l *slog.Logger) QueueOption {
return func(c *queueConfig) { c.logger = l }
}
// EnqueueOption configures a single Enqueue call.
type EnqueueOption func(*enqueueConfig)
type enqueueConfig struct {
runAt *time.Time
status *TaskStatus
ignoreDuplicates bool
}
// WithRunAt schedules the task for a specific time instead of now.
func WithRunAt(t time.Time) EnqueueOption {
return func(c *enqueueConfig) { c.runAt = &t }
}
// WithIgnoreDuplicates silently ignores the enqueue if a task with the
// same queue+hash already exists (ON CONFLICT DO NOTHING).
func WithIgnoreDuplicates() EnqueueOption {
return func(c *enqueueConfig) { c.ignoreDuplicates = true }
}
// WithStatus enqueues the task with a non-default status (e.g. Disabled).
func WithStatus(s TaskStatus) EnqueueOption {
return func(c *enqueueConfig) { c.status = &s }
}