-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathinterrupt.go
50 lines (43 loc) · 1.85 KB
/
interrupt.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
package inferable
// VALID_INTERRUPT_TYPES defines the valid types of interrupts that can occur during workflow execution.
type VALID_INTERRUPT_TYPES string
const (
// APPROVAL indicates an interrupt that requires user approval to continue.
APPROVAL VALID_INTERRUPT_TYPES = "approval"
// GENERAL indicates a general interrupt that can be used for various purposes.
GENERAL VALID_INTERRUPT_TYPES = "general"
)
// Interrupt represents an interruption in the normal flow of a workflow execution.
// Interrupts can be used to pause execution for approval or to handle exceptional conditions.
type Interrupt struct {
// Type specifies the kind of interrupt.
Type VALID_INTERRUPT_TYPES `json:"type"`
// Message provides additional context about the interrupt.
Message string `json:"message,omitempty"`
}
// Error implements the error interface, allowing Interrupts to be used as errors.
// This enables interrupts to be returned from functions that return errors.
func (i *Interrupt) Error() string {
if i.Message != "" {
return i.Message
}
return string(i.Type) + " interrupt"
}
// NewInterrupt creates a new Interrupt with the specified type and message.
// This is a general constructor for creating interrupts.
func NewInterrupt(typ VALID_INTERRUPT_TYPES, message string) *Interrupt {
return &Interrupt{
Type: typ,
Message: message,
}
}
// ApprovalInterrupt creates a new approval interrupt with the specified message.
// Approval interrupts are used when user approval is required to continue execution.
func ApprovalInterrupt(message string) *Interrupt {
return NewInterrupt(APPROVAL, message)
}
// GeneralInterrupt creates a new general interrupt with the specified message.
// General interrupts can be used for various purposes that require interrupting workflow execution.
func GeneralInterrupt(message string) *Interrupt {
return NewInterrupt(GENERAL, message)
}