Skip to content

Commit 5b943f0

Browse files
committed
enhanced logger
1 parent dfda37a commit 5b943f0

File tree

6 files changed

+472
-67
lines changed

6 files changed

+472
-67
lines changed

model/task.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package model
33
// Task represents a group of action
44
type Task struct {
55
*AbstractNode `yaml:",inline"` //abstract node
6+
*MetaTag `yaml:",inline"` //optional template tag propagated to task
67
Actions []*Action ` yaml:",omitempty"` //actions
78
*TasksNode ` yaml:",inline"`
89
Fail bool ` yaml:",omitempty"` //controls if return fail status workflow on catch task
@@ -34,6 +35,10 @@ func (t *Task) Clone() *Task {
3435
}
3536
result.TasksNode = t.TasksNode.Clone()
3637
result.AbstractNode = t.AbstractNode.Clone()
38+
if t.MetaTag != nil {
39+
tag := *t.MetaTag
40+
result.MetaTag = &tag
41+
}
3742
return &result
3843
}
3944

model/task_events.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package model
2+
3+
// TaskStartEvent represents the start of a task within a workflow.
4+
type TaskStartEvent struct {
5+
WorkflowName string `json:",omitempty"`
6+
OwnerURL string `json:",omitempty"`
7+
TaskName string `json:",omitempty"`
8+
TaskPath []string `json:",omitempty"`
9+
SessionID string `json:",omitempty"`
10+
Index int `json:",omitempty"`
11+
TemplateTag *MetaTag `json:",omitempty"`
12+
}
13+
14+
// NewTaskStartEvent creates a new TaskStartEvent.
15+
func NewTaskStartEvent(workflowName, ownerURL, taskName string, taskPath []string, sessionID string, index int, templateTag *MetaTag) *TaskStartEvent {
16+
return &TaskStartEvent{
17+
WorkflowName: workflowName,
18+
OwnerURL: ownerURL,
19+
TaskName: taskName,
20+
TaskPath: taskPath,
21+
SessionID: sessionID,
22+
Index: index,
23+
TemplateTag: templateTag,
24+
}
25+
}
26+
27+
// TaskEndEvent represents the end of a task within a workflow.
28+
type TaskEndEvent struct {
29+
WorkflowName string `json:",omitempty"`
30+
OwnerURL string `json:",omitempty"`
31+
TaskName string `json:",omitempty"`
32+
TaskPath []string `json:",omitempty"`
33+
SessionID string `json:",omitempty"`
34+
Index int `json:",omitempty"`
35+
Status string `json:",omitempty"`
36+
Error string `json:",omitempty"`
37+
}
38+
39+
// NewTaskEndEvent creates a new TaskEndEvent.
40+
func NewTaskEndEvent(workflowName, ownerURL, taskName string, taskPath []string, sessionID string, index int, status, errMsg string) *TaskEndEvent {
41+
return &TaskEndEvent{
42+
WorkflowName: workflowName,
43+
OwnerURL: ownerURL,
44+
TaskName: taskName,
45+
TaskPath: taskPath,
46+
SessionID: sessionID,
47+
Index: index,
48+
Status: status,
49+
Error: errMsg,
50+
}
51+
}
52+
53+
// TaskAsyncStartEvent denotes that a task has launched asynchronous actions.
54+
type TaskAsyncStartEvent struct {
55+
TaskPath []string `json:",omitempty"`
56+
Expected int `json:",omitempty"`
57+
SessionID string `json:",omitempty"`
58+
}
59+
60+
// NewTaskAsyncStartEvent creates a new TaskAsyncStartEvent.
61+
func NewTaskAsyncStartEvent(taskPath []string, expected int, sessionID string) *TaskAsyncStartEvent {
62+
return &TaskAsyncStartEvent{TaskPath: taskPath, Expected: expected, SessionID: sessionID}
63+
}
64+
65+
// TaskAsyncDoneEvent denotes completion of asynchronous actions within a task.
66+
type TaskAsyncDoneEvent struct {
67+
TaskPath []string `json:",omitempty"`
68+
Completed int `json:",omitempty"`
69+
SessionID string `json:",omitempty"`
70+
}
71+
72+
// NewTaskAsyncDoneEvent creates a new TaskAsyncDoneEvent.
73+
func NewTaskAsyncDoneEvent(taskPath []string, completed int, sessionID string) *TaskAsyncDoneEvent {
74+
return &TaskAsyncDoneEvent{TaskPath: taskPath, Completed: completed, SessionID: sessionID}
75+
}

model/template.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,15 @@ func flattenAction(parent *Task, task *Task, tag *Tag, description string) []*Ac
288288
if !isRootTask {
289289
tag.Group = parent.Name
290290
}
291+
// propagate template MetaTag to task itself
292+
if task.MetaTag == nil {
293+
task.MetaTag = &MetaTag{
294+
Tag: tag.Expand(tag.Name),
295+
TagIndex: tag.Iterator.Index(),
296+
TagID: tag.TagID(),
297+
TagDescription: description,
298+
}
299+
}
291300
if len(task.Actions) > 0 {
292301
result = task.Actions
293302
for i := range result {

service/workflow/lifecycle.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package workflow
2+
3+
// WorkflowStartEvent represents the start of a workflow, optionally nested.
4+
type WorkflowStartEvent struct {
5+
Name string `json:",omitempty"`
6+
OwnerURL string `json:",omitempty"`
7+
ParentName string `json:",omitempty"`
8+
ParentOwnerURL string `json:",omitempty"`
9+
SessionID string `json:",omitempty"`
10+
SelectedTasks string `json:",omitempty"`
11+
TagIDs string `json:",omitempty"`
12+
}
13+
14+
// NewWorkflowStartEvent creates a new WorkflowStartEvent.
15+
func NewWorkflowStartEvent(name, ownerURL, parentName, parentOwnerURL, sessionID, selectedTasks, tagIDs string) *WorkflowStartEvent {
16+
return &WorkflowStartEvent{
17+
Name: name,
18+
OwnerURL: ownerURL,
19+
ParentName: parentName,
20+
ParentOwnerURL: parentOwnerURL,
21+
SessionID: sessionID,
22+
SelectedTasks: selectedTasks,
23+
TagIDs: tagIDs,
24+
}
25+
}
26+
27+
// WorkflowEndEvent represents completion of a workflow.
28+
type WorkflowEndEvent struct {
29+
Name string `json:",omitempty"`
30+
OwnerURL string `json:",omitempty"`
31+
ParentName string `json:",omitempty"`
32+
ParentOwnerURL string `json:",omitempty"`
33+
SessionID string `json:",omitempty"`
34+
Status string `json:",omitempty"`
35+
Error string `json:",omitempty"`
36+
}
37+
38+
// NewWorkflowEndEvent creates a new WorkflowEndEvent.
39+
func NewWorkflowEndEvent(name, ownerURL, parentName, parentOwnerURL, sessionID, status, errMsg string) *WorkflowEndEvent {
40+
return &WorkflowEndEvent{
41+
Name: name,
42+
OwnerURL: ownerURL,
43+
ParentName: parentName,
44+
ParentOwnerURL: parentOwnerURL,
45+
SessionID: sessionID,
46+
Status: status,
47+
Error: errMsg,
48+
}
49+
}

0 commit comments

Comments
 (0)