forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheduler.go
64 lines (49 loc) · 1.46 KB
/
scheduler.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 services
import (
"context"
"errors"
config_proto "www.velocidex.com/golang/velociraptor/config/proto"
)
var (
global_scheduler Scheduler
)
func RegisterScheduler(scheduler Scheduler) {
mu.Lock()
defer mu.Unlock()
global_scheduler = scheduler
}
func GetSchedulerService(config_obj *config_proto.Config) (Scheduler, error) {
mu.Lock()
defer mu.Unlock()
if global_scheduler == nil {
return nil, errors.New("Scheduler not initialized")
}
return global_scheduler, nil
}
type SchedulerJob struct {
// The queue that is being scheduled.
Queue string
// A JSON encoded free form that is interpreted depending on the queue used.
Job string
OrgId string
// When the worker receives the job, on completion the worker must
// call the Done function with an error status.
Done func(result string, err error)
}
type JobResponse struct {
Job string
Err error
}
// Manages scheduling to distributed workers.
type Scheduler interface {
// Call this to register a worker. The caller will receive a
// channel over which jobs will be distributed. When the context
// is Done, the channel will be closed.
//
// When the worker completes the task they need to call job.Done()
RegisterWorker(ctx context.Context,
name, queue string, priority int) (chan SchedulerJob, error)
// Called by code that wants to schedule the job. The job will be
// scheduled to one of the available workers.
Schedule(ctx context.Context, job SchedulerJob) (chan JobResponse, error)
}