-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.go
71 lines (62 loc) · 1.79 KB
/
record.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
package dynamo_execution_repository
import (
"time"
"github.com/awlsring/texit/internal/pkg/domain/workflow"
)
const (
AttributeIdentifier = "identifier"
AttributeWorkflow = "workflow"
AttributeStatus = "status"
AttributeCreatedAt = "created_at"
AttributeUpdatedAt = "updated_at"
AttributeFinishedAt = "finished_at"
AttributeResults = "results"
AttributeTtl = "ttl"
)
type ExecutionDdbRecord struct {
Identifier string `dynamodbav:"identifier"`
Workflow string `dynamodbav:"workflow"`
Status string `dynamodbav:"status"`
CreatedAt time.Time `dynamodbav:"created_at"`
UpdatedAt time.Time `dynamodbav:"updated_at"`
FinishedAt *time.Time `dynamodbav:"finished_at,omitempty"`
Results *string `dynamodbav:"results,omitempty"`
}
func recordFromExecution(e *workflow.Execution) *ExecutionDdbRecord {
var results string
if e.Results != "" {
results = e.Results.String()
}
return &ExecutionDdbRecord{
Identifier: e.Identifier.String(),
Workflow: e.Workflow.String(),
Status: e.Status.String(),
CreatedAt: e.Created,
UpdatedAt: e.Updated,
FinishedAt: e.Finished,
Results: &results,
}
}
func (n *ExecutionDdbRecord) ToExecution() *workflow.Execution {
wf, err := workflow.WorkflowNameFromString(n.Workflow)
if err != nil {
wf = workflow.WorkflowNameUnknown
}
status, err := workflow.StatusFromString(n.Status)
if err != nil {
status = workflow.StatusUnknown
}
results := workflow.SerializedExecutionResult("")
if n.Results != nil {
results = workflow.SerializedExecutionResult(*n.Results)
}
return &workflow.Execution{
Identifier: workflow.ExecutionIdentifier(n.Identifier),
Workflow: wf,
Status: status,
Created: n.CreatedAt,
Updated: n.UpdatedAt,
Finished: n.FinishedAt,
Results: results,
}
}