-
Notifications
You must be signed in to change notification settings - Fork 7
/
worker.go
49 lines (40 loc) · 1.77 KB
/
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
47
48
49
package v1batch
import (
"net/http"
v1payload "github.com/nerdalize/nerd/nerd/client/batch/v1/payload"
)
//ClientWorkerInterface is an interface for placement of project
type ClientWorkerInterface interface {
StartWorker(projectID, image, queueID string, env map[string]string, inputDatasetID string) (output *v1payload.StartWorkerOutput, err error)
StopWorker(projectID, workerID string) (output *v1payload.StopWorkerOutput, err error)
ListWorkers(projectID string) (output *v1payload.ListWorkersOutput, err error)
}
//StartWorker will create worker
func (c *Client) StartWorker(projectID, image, queueID string, env map[string]string, inputDatasetID string) (output *v1payload.StartWorkerOutput, err error) {
output = &v1payload.StartWorkerOutput{}
input := &v1payload.StartWorkerInput{
ProjectID: projectID,
Image: image,
QueueID: queueID,
InputDatasetID: inputDatasetID,
Env: env,
}
return output, c.doRequest(http.MethodPost, createPath(projectID, workersEndpoint), input, output)
}
//StopWorker will delete worker a worker with the provided id
func (c *Client) StopWorker(projectID, workerID string) (output *v1payload.StopWorkerOutput, err error) {
output = &v1payload.StopWorkerOutput{}
input := &v1payload.StopWorkerInput{
ProjectID: projectID,
WorkerID: workerID,
}
return output, c.doRequest(http.MethodDelete, createPath(projectID, workersEndpoint, workerID), input, output)
}
// ListWorkers will return all tasks in a worker
func (c *Client) ListWorkers(projectID string) (output *v1payload.ListWorkersOutput, err error) {
output = &v1payload.ListWorkersOutput{}
input := &v1payload.ListWorkersInput{
ProjectID: projectID,
}
return output, c.doRequest(http.MethodGet, createPath(projectID, workersEndpoint), input, output)
}