added stop task

This commit is contained in:
Marvin Zhang
2019-03-09 16:18:39 +08:00
parent 1821c31cf7
commit 8d4ccddd8c
3 changed files with 27 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import json
import requests
from celery.worker.control import revoke
from constants.task import TaskStatus
from db.manager import db_manager
@@ -112,3 +113,10 @@ class TaskApi(BaseApi):
'fields': fields,
'items': items
})
def stop(self, id):
revoke(id, terminate=True)
return {
'id': id,
'status': 'ok',
}

View File

@@ -38,7 +38,8 @@
</el-form>
</el-row>
<el-row class="button-container">
<el-button type="danger" @click="onRestart">Restart</el-button>
<el-button v-if="isRunning" type="danger" @click="onStop">Stop</el-button>
<!--<el-button type="danger" @click="onRestart">Restart</el-button>-->
</el-row>
</div>
</template>
@@ -53,10 +54,19 @@ export default {
computed: {
...mapState('task', [
'taskForm'
])
]),
isRunning () {
return !['SUCCESS', 'FAILURE'].includes(this.taskForm.status)
}
},
methods: {
Restart () {
onRestart () {
},
onStop () {
this.$store.dispatch('task/stopTask', this.$route.params.id)
.then(() => {
this.$message.success(`Task "${this.$route.params.id}" has been sent signal to stop`)
})
}
}
}

View File

@@ -57,6 +57,12 @@ const actions = {
dispatch('getTaskList')
})
},
stopTask ({ state, dispatch }, id) {
return request.post(`/tasks/${id}/stop`)
.then(() => {
dispatch('getTaskList')
})
},
getTaskLog ({ state, commit }, id) {
return request.get(`/tasks/${id}/get_log`)
.then(response => {