/
generic_worker.go
46 lines (32 loc) · 1.27 KB
/
generic_worker.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
package finn
import "time"
// GenericWorker is the interface that all workers using Finn must match
type GenericWorker interface {
// Name returns the name of the worker
Name() string
// Run performs the actual work.
// Returns an error and whether to retry or not (bool)
Run() (error, bool)
// NewInstance returns a new instance of the worker
NewInstance() GenericWorker
// RunDelay returns the duration to sleep before running
RunDelay() time.Duration
// RetryDelay returns the duration to wait until the retry should start
RetryDelay(int) time.Duration
// RetryDelaySeconds returns the base number of seconds to wait before retrying
RetryDelaySeconds() int
// StartTime returns the time at which the worker should start running
StartTime() time.Time
// SetStartStamp sets the time at which the worker should start running
SetStartStamp(int64)
// NextStartStamp returns the next time the worker should start, based on RetryDelay()
NextStartStamp(int) int64
// Attempts returns the run attempt number
Attempts() int
// MaxAttempts returns the maximum number of attempts
MaxAttempts() int
// IncreaseAttempts increments the attempts counter by one
IncreaseAttempts()
// TopicName returns the queue/topic that the worker should listen on
TopicName() string
}