forked from goharbor/harbor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
131 lines (114 loc) · 3.8 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright 2018 The Harbor Authors. All rights reserved.
package pool
import "github.com/vmware/harbor/src/jobservice/models"
//Interface for worker pool.
//More like a driver to transparent the lower queue.
type Interface interface {
//Start to serve
Start()
//Register job to the pool.
//
//name string : job name for referring
//job interface{}: job handler which must implement the job.Interface.
//
//Return:
// error if failed to register
RegisterJob(name string, job interface{}) error
//Register multiple jobs.
//
//jobs map[string]interface{}: job map, key is job name and value is job handler.
//
//Return:
// error if failed to register
RegisterJobs(jobs map[string]interface{}) error
//Enqueue job
//
//jobName string : the name of enqueuing job
//params models.Parameters : parameters of enqueuing job
//isUnique bool : specify if duplicated job will be discarded
//
//Returns:
// models.JobStats: the stats of enqueuing job if succeed
// error : if failed to enqueue
Enqueue(jobName string, params models.Parameters, isUnique bool) (models.JobStats, error)
//Schedule job to run after the specified interval (seconds).
//
//jobName string : the name of enqueuing job
//runAfterSeconds uint64 : the waiting interval with seconds
//params models.Parameters : parameters of enqueuing job
//isUnique bool : specify if duplicated job will be discarded
//
//Returns:
// models.JobStats: the stats of enqueuing job if succeed
// error : if failed to enqueue
Schedule(jobName string, params models.Parameters, runAfterSeconds uint64, isUnique bool) (models.JobStats, error)
//Schedule the job periodically running.
//
//jobName string : the name of enqueuing job
//params models.Parameters : parameters of enqueuing job
//cronSetting string : the periodic duration with cron style like '0 * * * * *'
//
//Returns:
// models.JobStats: the stats of enqueuing job if succeed
// error : if failed to enqueue
PeriodicallyEnqueue(jobName string, params models.Parameters, cronSetting string) (models.JobStats, error)
//Return the status info of the pool.
//
//Returns:
// models.JobPoolStats : the stats info of all running pools
// error : failed to check
Stats() (models.JobPoolStats, error)
//Check if the job has been already registered.
//
//name string : name of job
//
//Returns:
// interface{} : the job type of the known job if it's existing
// bool : if the known job requires parameters
IsKnownJob(name string) (interface{}, bool)
//Validate the parameters of the known job
//
//jobType interface{} : type of known job
// params map[string]interface{} : parameters of known job
//
//Return:
// error if parameters are not valid
ValidateJobParameters(jobType interface{}, params map[string]interface{}) error
//Get the stats of the specified job
//
//jobID string : ID of the enqueued job
//
//Returns:
// models.JobStats : job stats data
// error : error returned if meet any problems
GetJobStats(jobID string) (models.JobStats, error)
//Stop the job
//
//jobID string : ID of the enqueued job
//
//Return:
// error : error returned if meet any problems
StopJob(jobID string) error
//Cancel the job
//
//jobID string : ID of the enqueued job
//
//Return:
// error : error returned if meet any problems
CancelJob(jobID string) error
//Retry the job
//
//jobID string : ID of the enqueued job
//
//Return:
// error : error returned if meet any problems
RetryJob(jobID string) error
//Register hook
//
//jobID string : ID of job
//hookURL string : the hook url
//
//Return:
// error : error returned if meet any problems
RegisterHook(jobID string, hookURL string) error
}