-
Notifications
You must be signed in to change notification settings - Fork 15
/
backend.go
79 lines (70 loc) · 2.12 KB
/
backend.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
package dingo
/*Backend interface is composed of Reporter/Store
*/
type Backend interface {
Reporter
Store
}
/*ReportEvenlope is the standard package sent through the channel to Reporter. The main requirement to fit
is to allow Reporter can know the meta info of the byte stream to send.
*/
type ReportEnvelope struct {
ID Meta
Body []byte
}
/*ReportEvent are those IDs of events that might be sent to ReporterHook
*/
var ReporterEvent = struct {
// a sequence of reports from this task is about to fire.
BeforeReport int
}{
1,
}
/*Reporter is responsible for sending reports to backend(s). The interaction between
Reporter(s) and dingo are asynchronous by channels.
*/
type Reporter interface {
// hook for listening events from dingo
// parameter:
// - eventID: which event?
// - payload: corresponding payload, its type depends on 'eventID'
// returns:
// - err: errors
ReporterHook(eventID int, payload interface{}) (err error)
// attach a report channel to backend. what dingo can promise is:
// - all reports belongs to the same task(name, id) would be sent through the same channel
//
// parameters:
// - name: all reports sent through this channel would be this name
// - reports: a input channel to receive reports from dingo.
// returns:
// - err: errors
Report(name string, reports <-chan *ReportEnvelope) (id int, err error)
}
/*StoreEvent are those IDs of events that might be sent to StoreHook
*/
var StoreEvent = struct {
}{}
/*Store is responsible for receiving reports from backend(s)
*/
type Store interface {
// hook for listening events from dingo
// parameter:
// - eventID: which event?
// - payload: corresponding payload, its type depends on 'eventID'
// returns:
// - err: errors
StoreHook(eventID int, payload interface{}) (err error)
// polling reports for tasks
//
// parameters:
// - meta: the meta info of that task to be polled.
// returns:
// - reports: the output channel for dingo to receive reports.
Poll(meta Meta) (reports <-chan []byte, err error)
// Stop monitoring that task
//
// parameters:
// - id the meta info of that task/report to stop polling.
Done(meta Meta) error
}