Skip to content

Commit b3afa12

Browse files
committed
refactoring, code cleanup
1 parent 37c0814 commit b3afa12

File tree

2 files changed

+39
-42
lines changed

2 files changed

+39
-42
lines changed

lib/app/Task.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ type Task struct {
3535
FromRemote bool
3636
}
3737

38+
type TaskReference struct {
39+
Task string `yaml:"task"`
40+
}
41+
42+
type ScheduledTask struct {
43+
Task string `yaml:"task"`
44+
Cron string `yaml:"cron"`
45+
}
46+
3847
func (task *Task) CanRunOnCurrentPlatform() bool {
3948
if task.Platforms == nil || len(task.Platforms) == 0 {
4049
return true
@@ -185,3 +194,19 @@ func (task *Task) Run(synchronous bool) {
185194

186195
App.ProcessMap.Store(task.Uuid, cmd)
187196
}
197+
198+
func (tr *TaskReference) TaskId() string {
199+
if App.JsEngine.IsEvaluatableScriptString(tr.Task) {
200+
return App.JsEngine.Evaluate(tr.Task).(string)
201+
}
202+
203+
return tr.Task
204+
}
205+
206+
func (st *ScheduledTask) TaskId() string {
207+
if App.JsEngine.IsEvaluatableScriptString(st.Task) {
208+
return App.JsEngine.Evaluate(st.Task).(string)
209+
}
210+
211+
return st.Task
212+
}

lib/app/workflow.go

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@ import (
1414
)
1515

1616
type StackupWorkflow struct {
17-
Name string `yaml:"name"`
18-
Description string `yaml:"description"`
19-
Version string `yaml:"version"`
20-
Settings *WorkflowSettings `yaml:"settings"`
21-
Init string `yaml:"init"`
22-
Preconditions []*Precondition `yaml:"preconditions"`
23-
Tasks []*Task `yaml:"tasks"`
24-
TaskList *lla.List
25-
Startup []TaskReference `yaml:"startup"`
26-
Shutdown []TaskReference `yaml:"shutdown"`
27-
Servers []TaskReference `yaml:"servers"`
28-
Scheduler []ScheduledTask `yaml:"scheduler"`
29-
Includes []*WorkflowInclude `yaml:"includes"`
30-
State *StackupWorkflowState
31-
RemoteTemplateIndex *RemoteTemplateIndex
17+
Name string `yaml:"name"`
18+
Description string `yaml:"description"`
19+
Version string `yaml:"version"`
20+
Settings *WorkflowSettings `yaml:"settings"`
21+
Init string `yaml:"init"`
22+
Preconditions []*Precondition `yaml:"preconditions"`
23+
Tasks []*Task `yaml:"tasks"`
24+
TaskList *lla.List
25+
Startup []TaskReference `yaml:"startup"`
26+
Shutdown []TaskReference `yaml:"shutdown"`
27+
Servers []TaskReference `yaml:"servers"`
28+
Scheduler []ScheduledTask `yaml:"scheduler"`
29+
Includes []*WorkflowInclude `yaml:"includes"`
30+
State *StackupWorkflowState
3231
}
3332

3433
type WorkflowInclude struct {
@@ -72,15 +71,6 @@ type Precondition struct {
7271
MaxRetries *int `yaml:"max-retries,omitempty"`
7372
}
7473

75-
type TaskReference struct {
76-
Task string `yaml:"task"`
77-
}
78-
79-
type ScheduledTask struct {
80-
Task string `yaml:"task"`
81-
Cron string `yaml:"cron"`
82-
}
83-
8474
func GetState() *StackupWorkflowState {
8575
return App.Workflow.State
8676
}
@@ -367,8 +357,6 @@ func (workflow *StackupWorkflow) RemoveTasks(uuidsToRemove []string) {
367357
}
368358

369359
func (workflow *StackupWorkflow) ProcessIncludes() {
370-
workflow.RemoteTemplateIndex = &RemoteTemplateIndex{Loaded: false}
371-
372360
// set default value for verify checksum to true
373361
for _, wi := range workflow.Includes {
374362
if wi.VerifyChecksum == nil {
@@ -470,19 +458,3 @@ func (workflow *StackupWorkflow) ProcessInclude(include *WorkflowInclude) bool {
470458

471459
return true
472460
}
473-
474-
func (tr *TaskReference) TaskId() string {
475-
if App.JsEngine.IsEvaluatableScriptString(tr.Task) {
476-
return App.JsEngine.Evaluate(tr.Task).(string)
477-
}
478-
479-
return tr.Task
480-
}
481-
482-
func (st *ScheduledTask) TaskId() string {
483-
if App.JsEngine.IsEvaluatableScriptString(st.Task) {
484-
return App.JsEngine.Evaluate(st.Task).(string)
485-
}
486-
487-
return st.Task
488-
}

0 commit comments

Comments
 (0)