From 39820fccde7c828d84af1d99362dee8489006eaa Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Tue, 18 Jun 2019 13:15:56 +0800 Subject: [PATCH] fixed issue https://github.com/tikazyq/crawlab/issues/54 --- crawlab/routes/tasks.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/crawlab/routes/tasks.py b/crawlab/routes/tasks.py index a318803b..5d1ff473 100644 --- a/crawlab/routes/tasks.py +++ b/crawlab/routes/tasks.py @@ -192,6 +192,31 @@ class TaskApi(BaseApi): } def stop(self, id): + """ + Send stop signal to a specific node + :param id: task_id + """ + task = db_manager.get('tasks', id=id) + node = db_manager.get('nodes', id=task['node_id']) + r = requests.get('http://%s:%s/api/tasks/%s/on_stop' % ( + node['ip'], + node['port'], + id + )) + if r.status_code == 200: + return { + 'status': 'ok', + 'message': 'success' + } + else: + data = json.loads(r.content) + return { + 'code': 500, + 'status': 'ok', + 'error': data['error'] + }, 500 + + def on_stop(self, id): """ Stop the task in progress. :param id: