mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 15:29:28 +01:00
feat: add status starting
This commit is contained in:
parent
0522ad169f
commit
aef7cbca04
@ -130,7 +130,15 @@ func StopTask(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := helpers.TaskPool(r).StopTask(targetTask)
|
||||
var stopObj struct {
|
||||
Force bool `json:"force"`
|
||||
}
|
||||
|
||||
if !helpers.Bind(w, r, &stopObj) {
|
||||
return
|
||||
}
|
||||
|
||||
err := helpers.TaskPool(r).StopTask(targetTask, stopObj.Force)
|
||||
if err != nil {
|
||||
helpers.WriteError(w, err)
|
||||
return
|
||||
|
@ -51,7 +51,7 @@ func GetRunner(w http.ResponseWriter, r *http.Request) {
|
||||
continue
|
||||
}
|
||||
|
||||
if tsk.Task.Status == db.TaskRunningStatus {
|
||||
if tsk.Task.Status == db.TaskStartingStatus {
|
||||
|
||||
data.NewJobs = append(data.NewJobs, runners.JobData{
|
||||
Username: tsk.Username,
|
||||
|
@ -8,6 +8,7 @@ type TaskStatus string
|
||||
|
||||
const (
|
||||
TaskWaitingStatus TaskStatus = "waiting"
|
||||
TaskStartingStatus TaskStatus = "starting"
|
||||
TaskRunningStatus TaskStatus = "running"
|
||||
TaskStoppingStatus TaskStatus = "stopping"
|
||||
TaskStoppedStatus TaskStatus = "stopped"
|
||||
|
@ -229,6 +229,9 @@ func (t *LocalJob) destroyKeys() {
|
||||
}
|
||||
|
||||
func (t *LocalJob) Run(username string, incomingVersion *string) (err error) {
|
||||
|
||||
t.SetStatus(db.TaskRunningStatus)
|
||||
|
||||
err = t.prepareRun()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -205,7 +205,7 @@ func CreateTaskPool(store db.Store) TaskPool {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *TaskPool) StopTask(targetTask db.Task) error {
|
||||
func (p *TaskPool) StopTask(targetTask db.Task, forceStop bool) error {
|
||||
tsk := p.GetTask(targetTask.ID)
|
||||
if tsk == nil { // task not active, but exists in database
|
||||
tsk = &TaskRunner{
|
||||
@ -221,7 +221,11 @@ func (p *TaskPool) StopTask(targetTask db.Task) error {
|
||||
} else {
|
||||
status := tsk.Task.Status
|
||||
|
||||
tsk.SetStatus(db.TaskStoppingStatus)
|
||||
if forceStop {
|
||||
tsk.SetStatus(db.TaskStoppedStatus)
|
||||
} else {
|
||||
tsk.SetStatus(db.TaskStoppingStatus)
|
||||
}
|
||||
|
||||
if status == db.TaskRunningStatus {
|
||||
tsk.kill()
|
||||
@ -328,7 +332,7 @@ func (p *TaskPool) AddTask(taskObj db.Task, userID *int, projectID int) (newTask
|
||||
err = taskRunner.populateDetails()
|
||||
if err != nil {
|
||||
taskRunner.Log("Error: " + err.Error())
|
||||
taskRunner.fail()
|
||||
taskRunner.SetStatus(db.TaskFailStatus)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ func (t *TaskRunner) SetStatus(status db.TaskStatus) {
|
||||
return
|
||||
}
|
||||
|
||||
switch t.Task.Status {
|
||||
switch t.Task.Status { // check old status
|
||||
case db.TaskRunningStatus:
|
||||
if status == db.TaskWaitingStatus {
|
||||
//panic("running TaskRunner cannot be " + status)
|
||||
@ -81,18 +81,13 @@ func (t *TaskRunner) SetStatus(status db.TaskStatus) {
|
||||
return
|
||||
}
|
||||
|
||||
//if t.Task.Status == db.TaskStoppingStatus {
|
||||
// switch status {
|
||||
// case db.TaskFailStatus:
|
||||
// status = db.TaskStoppedStatus
|
||||
// case db.TaskStoppedStatus:
|
||||
// default:
|
||||
// panic("stopping TaskRunner cannot be " + status)
|
||||
// }
|
||||
//}
|
||||
|
||||
t.Task.Status = status
|
||||
|
||||
if status == db.TaskRunningStatus {
|
||||
now := time.Now()
|
||||
t.Task.Start = &now
|
||||
}
|
||||
|
||||
t.saveStatus()
|
||||
|
||||
if status == db.TaskFailStatus {
|
||||
@ -132,10 +127,6 @@ func (t *TaskRunner) kill() {
|
||||
t.job.Kill()
|
||||
}
|
||||
|
||||
func (t *TaskRunner) fail() {
|
||||
t.SetStatus(db.TaskFailStatus)
|
||||
}
|
||||
|
||||
func (t *TaskRunner) createTaskEvent() {
|
||||
objType := db.EventTask
|
||||
desc := "Task ID " + strconv.Itoa(t.Task.ID) + " (" + t.Template.Name + ")" + " finished - " + strings.ToUpper(string(t.Task.Status))
|
||||
@ -170,15 +161,13 @@ func (t *TaskRunner) run() {
|
||||
t.createTaskEvent()
|
||||
}()
|
||||
|
||||
// TODO: more details
|
||||
// Mark task as stopped if user stopped task during preparation (before task run).
|
||||
if t.Task.Status == db.TaskStoppingStatus {
|
||||
t.SetStatus(db.TaskStoppedStatus)
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
t.Task.Start = &now
|
||||
t.SetStatus(db.TaskRunningStatus)
|
||||
t.SetStatus(db.TaskStartingStatus)
|
||||
|
||||
objType := db.EventTask
|
||||
desc := "Task ID " + strconv.Itoa(t.Task.ID) + " (" + t.Template.Name + ")" + " is running"
|
||||
@ -199,12 +188,6 @@ func (t *TaskRunner) run() {
|
||||
t.Log("Started: " + strconv.Itoa(t.Task.ID))
|
||||
t.Log("Run TaskRunner with template: " + t.Template.Name + "\n")
|
||||
|
||||
// Mark task as stopped if user stops task during preparation (before task run).
|
||||
if t.Task.Status == db.TaskStoppingStatus {
|
||||
t.SetStatus(db.TaskStoppedStatus)
|
||||
return
|
||||
}
|
||||
|
||||
var username string
|
||||
var incomingVersion *string
|
||||
|
||||
@ -225,7 +208,7 @@ func (t *TaskRunner) run() {
|
||||
|
||||
if err != nil {
|
||||
t.Log("Running playbook failed: " + err.Error())
|
||||
t.fail()
|
||||
t.SetStatus(db.TaskFailStatus)
|
||||
return
|
||||
}
|
||||
|
||||
@ -262,7 +245,7 @@ func (t *TaskRunner) prepareError(err error, errMsg string) error {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.fail()
|
||||
t.SetStatus(db.TaskFailStatus)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,12 @@
|
||||
<v-btn
|
||||
color="error"
|
||||
style="position: absolute; bottom: 10px; right: 10px;"
|
||||
v-if="item.status === 'running' || item.status === 'waiting'"
|
||||
@click="stopTask()"
|
||||
v-if="canStop"
|
||||
@click="stopTask(item.status === 'stopping')"
|
||||
>
|
||||
{{ $t('stop') }}
|
||||
{{ item.status === 'stopping' ? $t('forceStop') : $t('stop') }}
|
||||
</v-btn>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -139,6 +140,7 @@ export default {
|
||||
user: {},
|
||||
};
|
||||
},
|
||||
|
||||
watch: {
|
||||
async itemId() {
|
||||
this.reset();
|
||||
@ -150,17 +152,27 @@ export default {
|
||||
await this.loadData();
|
||||
},
|
||||
},
|
||||
|
||||
computed: {
|
||||
canStop() {
|
||||
return ['running', 'stopping', 'waiting', 'starting'].includes(this.item.status);
|
||||
},
|
||||
},
|
||||
|
||||
async created() {
|
||||
socket.addListener((data) => this.onWebsocketDataReceived(data));
|
||||
await this.loadData();
|
||||
},
|
||||
|
||||
methods: {
|
||||
async stopTask() {
|
||||
async stopTask(force) {
|
||||
await axios({
|
||||
method: 'post',
|
||||
url: `/api/project/${this.projectId}/tasks/${this.itemId}/stop`,
|
||||
responseType: 'json',
|
||||
data: {
|
||||
force,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
|
@ -10,6 +10,7 @@ import IndeterminateProgressCircular from '@/components/IndeterminateProgressCir
|
||||
|
||||
const TaskStatus = Object.freeze({
|
||||
WAITING: 'waiting',
|
||||
STARTING: 'starting',
|
||||
RUNNING: 'running',
|
||||
SUCCESS: 'success',
|
||||
ERROR: 'error',
|
||||
@ -28,6 +29,8 @@ export default {
|
||||
switch (status) {
|
||||
case TaskStatus.WAITING:
|
||||
return 'mdi-alarm';
|
||||
case TaskStatus.STARTING:
|
||||
return 'mdi-play-circle';
|
||||
case TaskStatus.RUNNING:
|
||||
return '';
|
||||
case TaskStatus.SUCCESS:
|
||||
@ -47,6 +50,8 @@ export default {
|
||||
switch (status) {
|
||||
case TaskStatus.WAITING:
|
||||
return 'Waiting';
|
||||
case TaskStatus.STARTING:
|
||||
return 'Starting...';
|
||||
case TaskStatus.RUNNING:
|
||||
return 'Running';
|
||||
case TaskStatus.SUCCESS:
|
||||
@ -66,6 +71,8 @@ export default {
|
||||
switch (status) {
|
||||
case TaskStatus.WAITING:
|
||||
return '';
|
||||
case TaskStatus.STARTING:
|
||||
return 'warning';
|
||||
case TaskStatus.RUNNING:
|
||||
return 'primary';
|
||||
case TaskStatus.SUCCESS:
|
||||
|
@ -133,6 +133,7 @@ export default {
|
||||
author: 'Author',
|
||||
duration: 'Duration',
|
||||
stop: 'Stop',
|
||||
forceStop: 'Force Stop',
|
||||
deleteTeamMember: 'Delete team member',
|
||||
team2: 'Team',
|
||||
newTeamMember: 'New Team Member',
|
||||
|
Loading…
Reference in New Issue
Block a user