-
Notifications
You must be signed in to change notification settings - Fork 145
/
worker.go
64 lines (46 loc) · 1.74 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package repository
import (
"time"
"github.com/hatchet-dev/hatchet/internal/repository/prisma/db"
)
type CreateWorkerOpts struct {
// The id of the dispatcher
DispatcherId string `validate:"required,uuid"`
// The name of the worker
Name string `validate:"required,hatchetName"`
// The name of the service
Services []string `validate:"dive,hatchetName"`
// A list of actions this worker can run
Actions []string `validate:"dive,actionId"`
}
type UpdateWorkerOpts struct {
// The status of the worker
Status *db.WorkerStatus
// When the last worker heartbeat was
LastHeartbeatAt *time.Time
// A list of actions this worker can run
Actions []string `validate:"dive,actionId"`
}
type WorkerWithStepCount struct {
Worker *db.WorkerModel
StepRunCount int
}
type ListWorkersOpts struct {
Action *string `validate:"omitempty,actionId"`
}
type WorkerRepository interface {
// ListWorkers lists workers for the tenant
ListWorkers(tenantId string, opts *ListWorkersOpts) ([]WorkerWithStepCount, error)
// ListRecentWorkerStepRuns lists recent step runs for a given worker
ListRecentWorkerStepRuns(tenantId, workerId string) ([]db.StepRunModel, error)
// CreateNewWorker creates a new worker for a given tenant.
CreateNewWorker(tenantId string, opts *CreateWorkerOpts) (*db.WorkerModel, error)
// UpdateWorker updates a worker for a given tenant.
UpdateWorker(tenantId, workerId string, opts *UpdateWorkerOpts) (*db.WorkerModel, error)
// DeleteWorker removes the worker from the database
DeleteWorker(tenantId, workerId string) error
// GetWorkerById returns a worker by its id.
GetWorkerById(workerId string) (*db.WorkerModel, error)
// AddStepRun assigns a step run to a worker.
AddStepRun(tenantId, workerId, stepRunId string) error
}