From 0df8d84105690651cf8a8f8d782f6e11ac0720f5 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Sat, 9 Mar 2019 16:18:39 +0800 Subject: [PATCH] added stop task --- crawlab/routes/tasks.py | 8 ++++++++ .../src/components/InfoView/TaskInfoView.vue | 16 +++++++++++++--- frontend/src/store/modules/task.js | 6 ++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/crawlab/routes/tasks.py b/crawlab/routes/tasks.py index 398bee15..17e5df6d 100644 --- a/crawlab/routes/tasks.py +++ b/crawlab/routes/tasks.py @@ -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', + } diff --git a/frontend/src/components/InfoView/TaskInfoView.vue b/frontend/src/components/InfoView/TaskInfoView.vue index a81174d2..44730dcf 100644 --- a/frontend/src/components/InfoView/TaskInfoView.vue +++ b/frontend/src/components/InfoView/TaskInfoView.vue @@ -38,7 +38,8 @@ - Restart + Stop + @@ -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`) + }) } } } diff --git a/frontend/src/store/modules/task.js b/frontend/src/store/modules/task.js index 22e921d7..3e1e5b9c 100644 --- a/frontend/src/store/modules/task.js +++ b/frontend/src/store/modules/task.js @@ -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 => {