-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.go
45 lines (39 loc) · 1.12 KB
/
job.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
package qpool
import "time"
// Job represents work to be done
type Job struct {
ID string
Fn func() (any, error)
RetryPolicy *RetryPolicy
CircuitID string
CircuitConfig *CircuitBreakerConfig
Dependencies []string
TTL time.Duration
Attempt int
LastError error
DependencyRetryPolicy *RetryPolicy
StartTime time.Time
}
// JobOption is a function type for configuring jobs
type JobOption func(*Job)
// CircuitBreakerConfig defines configuration for a circuit breaker
type CircuitBreakerConfig struct {
MaxFailures int
ResetTimeout time.Duration
HalfOpenMax int
}
// WithDependencyRetry configures retry behavior for dependencies
func WithDependencyRetry(attempts int, strategy RetryStrategy) JobOption {
return func(j *Job) {
j.DependencyRetryPolicy = &RetryPolicy{
MaxAttempts: attempts,
Strategy: strategy,
}
}
}
// WithDependencies configures job dependencies
func WithDependencies(dependencies []string) JobOption {
return func(j *Job) {
j.Dependencies = dependencies
}
}