-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathss_node_worker.go
140 lines (110 loc) · 3.21 KB
/
ss_node_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
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
132
133
134
135
136
137
138
139
140
package states
import (
am "github.com/pancsta/asyncmachine-go/pkg/machine"
ssrpc "github.com/pancsta/asyncmachine-go/pkg/rpc/states"
)
// WorkerStatesDef contains all the states of the Worker state machine.
type WorkerStatesDef struct {
*am.StatesBase
// errors
ErrWork string
ErrWorkTimeout string
ErrClient string
ErrSupervisor string
// basics
// Ready - Worker is able to perform work.
Ready string
// rpc
// LocalRpcReady - Supervisor RPC server is ready for connections.
LocalRpcReady string
// PublicRpcReady - Client RPC server is ready for connections.
PublicRpcReady string
// RpcReady - both RPC servers are ready.
RpcReady string
// SuperConnected - Worker is connected to the Supervisor.
SuperConnected string
// ServeClient - Worker is requested to accept a connection from client
// am.A["id"].
ServeClient string
// ClientConnected - Worker is connected to a client.
ClientConnected string
ClientSendPayload string
SuperSendPayload string
// work
Idle string
WorkRequested string
Working string
WorkReady string
// inherit from WorkerStatesDef
*ssrpc.WorkerStatesDef
}
// WorkerGroupsDef contains all the state groups of the Worker state machine.
type WorkerGroupsDef struct {
// WorkStatus represents work-related states, 1 active at a time. This group
// has to be bound by the implementation, e.g. using Add relation from custom
// work states.
WorkStatus S
}
// WorkerStruct represents all relations and properties of WorkerStates.
var WorkerStruct = StructMerge(
// inherit from BasicStruct
ssrpc.WorkerStruct,
am.Struct{
// errors
ssW.ErrWork: {Require: S{Exception}},
ssW.ErrWorkTimeout: {Require: S{Exception}},
ssW.ErrClient: {Require: S{Exception}},
ssW.ErrSupervisor: {Require: S{Exception}},
// piped
ssW.LocalRpcReady: {Require: S{ssW.Start}},
ssW.PublicRpcReady: {Require: S{ssW.Start}},
ssW.SuperConnected: {Require: S{ssW.Start}},
ssW.ClientConnected: {Require: S{ssW.Start}},
// basics
ssW.Ready: {Require: S{ssW.LocalRpcReady}},
// rpc
ssW.RpcReady: {
Auto: true,
Require: S{ssW.LocalRpcReady, ssW.PublicRpcReady},
},
ssW.ServeClient: {Require: S{ssW.PublicRpcReady}},
ssW.ClientSendPayload: {
Require: S{ssW.PublicRpcReady},
},
ssW.SuperSendPayload: {
Require: S{ssW.LocalRpcReady},
},
// disable SendPayload
ssW.SendPayload: {Add: S{ssW.ErrSendPayload, ssW.Exception}},
// work
ssW.Idle: {
Auto: true,
Require: S{ssW.Ready},
Remove: sgW.WorkStatus,
},
ssW.WorkRequested: {
Require: S{ssW.Ready},
Remove: sgW.WorkStatus,
},
ssW.Working: {
Require: S{ssW.Ready},
Remove: sgW.WorkStatus,
},
ssW.WorkReady: {
Require: S{ssW.Ready},
Remove: sgW.WorkStatus,
},
})
// EXPORTS AND GROUPS
var (
// ssW is worker states from WorkerStatesDef.
ssW = am.NewStates(WorkerStatesDef{})
// sgW is worker groups from WorkerGroupsDef.
sgW = am.NewStateGroups(WorkerGroupsDef{
WorkStatus: S{ssW.WorkRequested, ssW.Working, ssW.WorkReady, ssW.Idle},
})
// WorkerStates contains all the states for the Worker machine.
WorkerStates = ssW
// WorkerGroups contains all the state groups for the Worker machine.
WorkerGroups = sgW
)