Skip to content

Commit ef4fc55

Browse files
committed
Merge branch '2-13-stable' into 2-14-stable
2 parents e02c7c5 + 1b83be7 commit ef4fc55

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

services/tasks/LocalJob.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,35 @@ import (
1717
)
1818

1919
type LocalJob struct {
20-
// Received constant fields
2120
Task db.Task
2221
Template db.Template
2322
Inventory db.Inventory
2423
Repository db.Repository
2524
Environment db.Environment
26-
Secret string
27-
Logger task_logger.Logger
25+
Secret string // Secret contains secrets received from Survey variables
26+
Logger task_logger.Logger // Logger allows to send logs and status to the server
2827

2928
App db_lib.LocalApp
3029

31-
// Internal field
30+
killed bool // killed means that API request to stop the job has been received
3231
Process *os.Process
3332

3433
sshKeyInstallation db.AccessKeyInstallation
3534
becomeKeyInstallation db.AccessKeyInstallation
3635
vaultFileInstallations map[string]db.AccessKeyInstallation
3736
}
3837

38+
func (t *LocalJob) IsKilled() bool {
39+
return t.killed
40+
}
41+
3942
func (t *LocalJob) Kill() {
43+
t.killed = true
44+
4045
if t.Process == nil {
4146
return
4247
}
48+
4349
err := t.Process.Kill()
4450
if err != nil {
4551
t.Log(err.Error())
@@ -585,6 +591,11 @@ func (t *LocalJob) Run(username string, incomingVersion *string, alias string) (
585591
}
586592
}
587593

594+
if t.killed {
595+
t.SetStatus(task_logger.TaskStoppedStatus)
596+
return nil
597+
}
598+
588599
return t.App.Run(db_lib.LocalAppRunningArgs{
589600
CliArgs: args,
590601
EnvironmentVars: environmentVariables,

services/tasks/RemoteJob.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type RemoteJob struct {
1616
RunnerTag *string
1717
Task db.Task
1818
taskPool *TaskPool
19+
killed bool
1920
}
2021

2122
type runnerWebhookPayload struct {
@@ -162,5 +163,10 @@ func (t *RemoteJob) Run(username string, incomingVersion *string, alias string)
162163
}
163164

164165
func (t *RemoteJob) Kill() {
166+
t.killed = true
165167
// Do nothing because you can't kill remote process
166168
}
169+
170+
func (t *RemoteJob) IsKilled() bool {
171+
return t.killed
172+
}

services/tasks/TaskRunner.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
type Job interface {
2020
Run(username string, incomingVersion *string, alias string) error
2121
Kill()
22+
IsKilled() bool
2223
}
2324

2425
type TaskRunner struct {
@@ -177,8 +178,12 @@ func (t *TaskRunner) run() {
177178
err = t.job.Run(username, incomingVersion, t.Alias)
178179

179180
if err != nil {
180-
t.Log("Running app failed: " + err.Error())
181-
t.SetStatus(task_logger.TaskFailStatus)
181+
if t.job.IsKilled() {
182+
t.SetStatus(task_logger.TaskStoppedStatus)
183+
} else {
184+
t.Log("Running app failed: " + err.Error())
185+
t.SetStatus(task_logger.TaskFailStatus)
186+
}
182187
return
183188
}
184189

0 commit comments

Comments
 (0)