From 46a6ecadd87f328a8a5ca6b9a594f42952ea1786 Mon Sep 17 00:00:00 2001 From: Yauhen Shulitski Date: Wed, 26 Feb 2020 00:01:34 +0100 Subject: [PATCH] :m: Add final tasks --- src/backend/build.go | 14 +++++++++++++- src/backend/job.go | 8 ++++++++ src/frontend/src/assets/configDescription.yaml | 8 ++++++++ src/frontend/src/components/TaskItem.vue | 7 +++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/backend/build.go b/src/backend/build.go index 3bead03..5350938 100644 --- a/src/backend/build.go +++ b/src/backend/build.go @@ -21,7 +21,7 @@ import ( ) // ItemStatus handles information about the item status (currently is used for -// both Builds and Tasks) +// both Builds and Tasks) and type of OnStatus changed tasks type ItemStatus string // StatusRunning ... @@ -39,6 +39,9 @@ const StatusPending = "pending" // StatusAborted ... const StatusAborted = "aborted" +// FinalTask is the task that is executed no matter what is the result of the build +const FinalTask = "finally" + // Build ... type Build struct { ID int @@ -96,11 +99,13 @@ func (b *Build) runOnStatusTasks(status ItemStatus) { if task.Kind == string(status) { task.Status = StatusRunning task.startedAt = time.Now() + b.BroadcastUpdate() status := b.runTask(task) task.Status = status task.duration = time.Since(task.startedAt) + b.BroadcastUpdate() } } } @@ -196,6 +201,8 @@ func (b *Build) runTask(task *Task) ItemStatus { // Abort message was recieved via channel if b.aborted { + // Toggle status back for OnStatus tasks + b.aborted = false return StatusAborted } @@ -384,6 +391,7 @@ func (b *Build) GetTasksStatus() []*TaskStatus { func (b *Build) SetBuildStatus(status ItemStatus) { b.Logger.Printf("Status: %s\n", status) b.Status = status + b.BroadcastUpdate() defer b.BroadcastUpdate() // Wait for pending task to finish before running anything else b.pendingTasksWG.Wait() @@ -417,21 +425,25 @@ func (b *Build) SetBuildStatus(status ItemStatus) { break case StatusAborted: b.runOnStatusTasks(status) + b.runOnStatusTasks(FinalTask) b.Duration = time.Since(b.StartedAt) b.Cleanup() break case StatusFailed: b.runOnStatusTasks(status) + b.runOnStatusTasks(FinalTask) b.Duration = time.Since(b.StartedAt) b.Cleanup() break case StatusFinished: b.CollectArtifacts() b.runOnStatusTasks(status) + b.runOnStatusTasks(FinalTask) b.Duration = time.Since(b.StartedAt) b.Cleanup() break } + } // CreateBuild creates Build instance and all necessary files and folders in wakespace diff --git a/src/backend/job.go b/src/backend/job.go index efb6d7a..dcc9720 100644 --- a/src/backend/job.go +++ b/src/backend/job.go @@ -90,6 +90,7 @@ type OnTasks struct { OnFailed []*Task `yaml:"on_failed"` OnAborted []*Task `yaml:"on_aborted"` OnFinished []*Task `yaml:"on_finished"` + Finally []*Task `yaml:"finally"` } // CreateJobFromFile reads job from a file @@ -150,6 +151,13 @@ func CreateJobFromFile(path string) (*Job, error) { job.Tasks = append(job.Tasks, ot.OnFinished...) } + if ot.Finally != nil { + for _, t := range ot.Finally { + t.Kind = "finally" + } + job.Tasks = append(job.Tasks, ot.Finally...) + } + // Assign tasks ids and status for i, t := range job.Tasks { t.ID = i diff --git a/src/frontend/src/assets/configDescription.yaml b/src/frontend/src/assets/configDescription.yaml index 496b386..bd34f86 100644 --- a/src/frontend/src/assets/configDescription.yaml +++ b/src/frontend/src/assets/configDescription.yaml @@ -13,6 +13,9 @@ tasks: # List of patterns according to https://golang.org/pkg/path/filepath/#Match # related to the workspace directory +# Note: +# - artifacts are collected only for builds with status `finished` +# - `on_finished` and `finally` tasks are executed after artifacts are collected artifacts: - "*.tar.gz" @@ -39,6 +42,11 @@ on_pending: - name: Log a call command: logger "Looking for a suitable cow" +# List of tasks that are always executed +finally: + - name: List all files + command: ls -alh + # Available environmetal variables: # WAKE_BUILD_ID - current build id, e.g. 169 # WAKE_BUILD_WORKSPACE - path to the build's workspace, e.g. ~/workspace/ diff --git a/src/frontend/src/components/TaskItem.vue b/src/frontend/src/components/TaskItem.vue index 481e9ce..d8a3c67 100644 --- a/src/frontend/src/components/TaskItem.vue +++ b/src/frontend/src/components/TaskItem.vue @@ -76,10 +76,10 @@ export default { return `task #${this.task.id}`; }, isVisible: function() { - // Show only "main" tasks or tasks that were started. For example, + // Show only "main" and "finally" tasks or tasks that were started. For example, // there is no need to show "finished" tasks if build failed because // they won't be executed anyway - if (this.task.kind === "main") { + if (this.task.kind === "main" || this.task.kind === "finally") { return true; } return !( @@ -226,4 +226,7 @@ section { .border-finished { border-left-color: $success-color; } +.border-finally { + border-left-color: $dark-color; +}