-
Notifications
You must be signed in to change notification settings - Fork 19
/
wait_timed_out.go
58 lines (46 loc) · 1.49 KB
/
wait_timed_out.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
package events
import (
"fmt"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/utils"
)
// TypeWaitTimedOut is the type of our wait timed out events
const TypeWaitTimedOut string = "wait_timed_out"
// WaitTimedOutEvent events are sent by the caller when a wait has timed out - i.e. they are sent instead of
// the item that the wait was waiting for
//
// {
// "type": "wait_timed_out",
// "created_on": "2006-01-02T15:04:05Z"
// }
//
// @event wait_timed_out
type WaitTimedOutEvent struct {
baseEvent
callerOnlyEvent
}
// NewWaitTimedOutEvent creates a new wait timed out event
func NewWaitTimedOutEvent() *WaitTimedOutEvent {
return &WaitTimedOutEvent{baseEvent: newBaseEvent()}
}
// Type returns the type of this event
func (e *WaitTimedOutEvent) Type() string { return TypeWaitTimedOut }
// Validate validates our event is valid and has all the assets it needs
func (e *WaitTimedOutEvent) Validate(assets flows.SessionAssets) error {
return nil
}
// Apply applies this event to the given run
func (e *WaitTimedOutEvent) Apply(run flows.FlowRun) error {
wait := run.Session().Wait()
if run.Status() != flows.RunStatusWaiting || wait == nil {
return fmt.Errorf("can only be applied to waiting runs")
}
if wait.Timeout() == nil || wait.TimeoutOn() == nil {
return fmt.Errorf("can only be applied when session wait has timeout")
}
if utils.Now().Before(*wait.TimeoutOn()) {
return fmt.Errorf("can't apply before wait has timed out")
}
run.SetInput(nil)
return nil
}