-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
46 lines (36 loc) · 853 Bytes
/
type.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 workers
import (
"context"
"errors"
"time"
)
type ChanSignal struct{}
type Status int
const (
StatusCreated Status = iota
StatusRunning
StatusStopped
)
var (
ErrWorkerNotRunning = errors.New("worker is not running")
)
type Job interface {
Id() string
Status() Status
Done() chan ChanSignal
// Func below should be called by worker
// Do should be blocking the process until the job is finished or canceled. ctx contains a job timeout
Do(ctx context.Context)
// Cancel should be blocking the process until the job is gracefully canceled. ctx contains a cancellation deadline
Cancel(ctx context.Context)
}
type Worker interface {
Start() error
Shutdown() error
Status() Status
Done() chan ChanSignal
GetJobTimeout() time.Duration
GetShutdownTimeout() time.Duration
Push(job Job) error
PushAndWait(job Job) error
}