-
Notifications
You must be signed in to change notification settings - Fork 2
/
interface.go
99 lines (73 loc) · 2.41 KB
/
interface.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package agscheduler
import (
"context"
"time"
)
// Defines the interface that each store must implement.
type Store interface {
// Store name.
Name() string
// Initialization functions for each store,
// called when the scheduler run `SetStore`.
Init() error
// Add job to this store.
AddJob(j Job) error
// Get the job from this store.
// @return error `JobNotFoundError` if there are no job.
GetJob(id string) (Job, error)
// Get all jobs from this store.
GetAllJobs() ([]Job, error)
// Update job in store with a newer version.
UpdateJob(j Job) error
// Delete the job from this store.
DeleteJob(id string) error
// Delete all jobs from this store.
DeleteAllJobs() error
// Get the earliest next run time of all the jobs stored in this store,
// or `time.Time{}` if there are no job.
// Used to set the wakeup interval for the scheduler.
GetNextRunTime() (time.Time, error)
// Clear all resources bound to this store.
Clear() error
}
// Defines the interface that each queue must implement.
type Queue interface {
// Queue name.
Name() string
// Initialization functions for each queue,
// called when the scheduler run `SetBroker`.
Init(ctx context.Context) error
// Push job to this queue.
PushJob(bJ []byte) error
// Pull job from this queue.
PullJob() <-chan []byte
// Count the number of jobs in this queue.
// @return -1, nil, if the queue does not support this feature or error.
CountJobs() (int, error)
// Clear all resources bound to this queue.
Clear() error
}
// Defines the interface that each backend must implement.
type Backend interface {
// Backend name.
Name() string
// Initialization functions for each backend,
// called when the scheduler run `SetBackend`.
Init() error
// Record the metadata of the job to this backend.
RecordMetadata(r Record) error
// Record the result of the job run to this backend.
RecordResult(id uint64, status string, result string) error
// Get records by job id from this backend.
// @return records, total, error.
GetRecords(jId string, page, pageSize int) ([]Record, int64, error)
// Get all records from this backend.
// @return records, total, error.
GetAllRecords(page, pageSize int) ([]Record, int64, error)
// Delete records by job id from this backend.
DeleteRecords(jId string) error
// Delete all records from this backend.
DeleteAllRecords() error
// Clear all resources bound to this backend.
Clear() error
}