Skip to content

Commit

Permalink
Support View class stop timeout from /tasks resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Jul 22, 2020
1 parent d67f26a commit 375ed71
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/labthings/default_views/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

from ..views import View
from ..views.marshalling import marshal_with
from ..views.args import use_args
from ..schema import TaskSchema
from ..find import current_labthing
from .. import fields


class TaskList(View):
Expand Down Expand Up @@ -46,21 +48,22 @@ def get(self, task_id):

return TaskSchema().dump(task)

def delete(self, task_id):
@use_args({"timeout": fields.Int()})
def delete(self, args, task_id):
"""Terminate a running task.
If the task is finished, deletes its entry.
:param task_id:
"""

timeout = args.get("timeout", None)
task_dict = current_labthing().actions.to_dict()

if task_id not in task_dict:
return abort(404) # 404 Not Found

task = task_dict.get(task_id)
task.stop(timeout=5)
task.stop(timeout=timeout)

return TaskSchema().dump(task)

0 comments on commit 375ed71

Please sign in to comment.