-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheduled_event.go
59 lines (50 loc) · 1.08 KB
/
scheduled_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
package scheduledevent
import (
"encoding/json"
"time"
"github.com/Maxson-dev/place-api/internal/pkg/cerror"
"github.com/google/uuid"
)
type ScheduledEvent struct {
ID uuid.UUID
Status Status
Datetime time.Time
Payload Payload
CreatedAt time.Time
Attempt int64
}
// New scheduledEvent constructor
func New(datetime time.Time, eventType string, payload []byte) (ScheduledEvent, error) {
switch eventType {
case string(SendNotification):
var p SendNotificationPayload
err := json.Unmarshal(payload, &p)
if err != nil {
return ScheduledEvent{}, cerror.ErrBadInput
}
return ScheduledEvent{
ID: uuid.New(),
Status: EventStatusNew,
Datetime: datetime,
Payload: p,
Attempt: 0,
CreatedAt: time.Now().UTC(),
}, nil
}
return ScheduledEvent{}, cerror.ErrBadInput
}
type Status uint8
const (
EventStatusNew Status = iota
EventStatusInProgress
EventStatusDone
EventStatusFailed
)
type Type string
const (
SendNotification Type = "SEND_NOTIFICATION" // whatever
)
type Payload interface {
IsScheduledEventPayload()
Type() Type
}