forked from taskgraph/taskgraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_interface.go
78 lines (61 loc) · 2.4 KB
/
task_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
package taskgraph
import (
"github.com/golang/protobuf/proto"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
// Task is a logic repersentation of a computing unit.
// Each task contain at least one Node.
// Each task has exact one master Node and might have multiple salve Nodes.
// All event handler functions and should be non-blocking.
type Task interface {
// This is useful to bring the task up to speed from scratch or if it recovers.
Init(taskID uint64, framework Framework)
// Task is finished up for exit. Last chance to save some task specific work.
Exit()
// Framework tells user task what current epoch is.
// This give the task an opportunity to cleanup and regroup.
EnterEpoch(ctx context.Context, epoch uint64)
// The meta/data notifications obey exactly-once semantics. Note that the same
// meta string will be notified only once even if you flag the meta more than once.
// TODO: one can also get this from channel.
MetaReady(ctx context.Context, fromID uint64, linkType, meta string)
// This is the callback when data from server is ready.
DataReady(ctx context.Context, fromID uint64, method string, output proto.Message)
CreateOutputMessage(methodName string) proto.Message
CreateServer() *grpc.Server
}
type UpdateLog interface {
UpdateID()
}
// Backupable is an interface that task need to implement if they want to have
// hot standby copy. This is another can of beans.
type Backupable interface {
// Some hooks that need for master slave etc.
BecamePrimary()
BecameBackup()
// Framework notify this copy to update. This should be the only way that
// one update the state of copy.
Update(log UpdateLog)
}
type GRPCHelper interface {
CreateOutputMessage(methodName string) proto.Message
CreateServer() *grpc.Server
}
// Master task is assumed to be fault tolerant.
type MasterTask interface {
Setup(framework MasterFrame)
Run(ctx context.Context)
// Corresponds to NotifyMaster
OnNotify(ctx context.Context, workerID uint64, method string, input proto.Message) (proto.Message, error)
GRPCHelper
}
type WorkerTask interface {
Setup(framework WorkerFrame, workerID uint64)
Run(ctx context.Context)
// Corresponds to NotifyWorker
OnNotify(ctx context.Context, method string, input proto.Message) (proto.Message, error)
// Corresponds to DataRequest
ServeData(ctx context.Context, workerID uint64, method string, input proto.Message) (proto.Message, error)
GRPCHelper
}