mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-04 21:29:36 +00:00
remove dependency on redis json
This commit is contained in:
@@ -4,9 +4,8 @@ functionality:
|
||||
- handle threads and locks
|
||||
"""
|
||||
|
||||
from common.src.ta_redis import RedisArchivist, TaskRedis
|
||||
from common.src.ta_redis import TaskRedis
|
||||
from task.celery import app as celery_app
|
||||
from task.src.task_config import TASK_CONFIG
|
||||
|
||||
|
||||
class TaskManager:
|
||||
@@ -96,20 +95,13 @@ class TaskCommand:
|
||||
|
||||
return message
|
||||
|
||||
def stop(self, task_id, message_key):
|
||||
def stop(self, task_id):
|
||||
"""
|
||||
send stop signal to task_id,
|
||||
needs to be implemented in task to take effect
|
||||
"""
|
||||
print(f"[task][{task_id}]: received STOP signal.")
|
||||
handler = TaskRedis()
|
||||
|
||||
task = handler.get_single(task_id)
|
||||
if not task["name"] in TASK_CONFIG:
|
||||
raise ValueError
|
||||
|
||||
handler.set_command(task_id, "STOP")
|
||||
RedisArchivist().set_message(message_key, "STOP", path=".command")
|
||||
TaskRedis().set_command(task_id, "STOP")
|
||||
|
||||
def kill(self, task_id):
|
||||
"""send kill signal to task_id"""
|
||||
|
||||
@@ -103,8 +103,7 @@ class TaskIDView(ApiBaseView):
|
||||
message = {"message": "task can not be stopped"}
|
||||
return Response(message, status=400)
|
||||
|
||||
message_key = self._build_message_key(task_conf, task_id)
|
||||
TaskCommand().stop(task_id, message_key)
|
||||
TaskCommand().stop(task_id)
|
||||
if command == "kill":
|
||||
if not task_conf.get("api_stop"):
|
||||
message = {"message": "task can not be killed"}
|
||||
@@ -114,10 +113,6 @@ class TaskIDView(ApiBaseView):
|
||||
|
||||
return Response({"message": "command sent"})
|
||||
|
||||
def _build_message_key(self, task_conf, task_id):
|
||||
"""build message key to forward command to notification"""
|
||||
return f"message:{task_conf.get('group')}:{task_id.split('-')[0]}"
|
||||
|
||||
|
||||
class ScheduleListView(ApiBaseView):
|
||||
"""resolves to /api/task/schedule/
|
||||
|
||||
Reference in New Issue
Block a user