forked from gree/futurama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
70 lines (60 loc) · 1.17 KB
/
event.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
package futurama
import (
"fmt"
"time"
)
const (
EventStatus_DEFAULT = 1 + iota
EventStatus_OK
EventStatus_CANCEL
EventStatus_ERROR
EventStatus_RETRY
)
var eventStatusText = []string{
"UNKNOWN",
"DEFAULT",
"OK",
"CANCEL",
"ERROR",
"RETRY",
}
type EventStatus uint32
func (self EventStatus) String() string {
if int(self) >= len(eventStatusText) {
return fmt.Sprintf("EXTENDED(%d)", self)
}
return eventStatusText[self]
}
type Event struct {
Id string
TriggerType string
TriggerTime time.Time
Owner string
Attempts int
Status EventStatus
Created time.Time
Updated time.Time
Completed time.Time
Locked time.Time
Data interface{}
timer *time.Timer
}
func NewEvent(triggerType string, triggerTime time.Time, data interface{}) *Event {
return &Event{
TriggerType: triggerType,
TriggerTime: triggerTime,
Status: EventStatus_DEFAULT,
Created: time.Now(),
Data: data,
}
}
func (self *Event) String() string {
return fmt.Sprintf("%s %d", self.Id, self.TriggerTime.Unix())
}
func (self *Event) Stop() {
self.timer.Stop()
self.timer = nil
}
func (self *Event) GetKey() string {
return self.Id
}