diff --git a/swh/scheduler/backend.py b/swh/scheduler/backend.py --- a/swh/scheduler/backend.py +++ b/swh/scheduler/backend.py @@ -494,7 +494,12 @@ @db_transaction() def set_status_tasks( - self, task_ids, status="disabled", next_run=None, db=None, cur=None + self, + task_ids: List[int], + status: str = "disabled", + next_run: Optional[datetime.datetime] = None, + db=None, + cur=None, ): """Set the tasks' status whose ids are listed. @@ -503,7 +508,7 @@ if not task_ids: return query = ["UPDATE task SET status = %s"] - args = [status] + args: List[Any] = [status] if next_run: query.append(", next_run = %s") args.append(next_run) diff --git a/swh/scheduler/cli/task.py b/swh/scheduler/cli/task.py --- a/swh/scheduler/cli/task.py +++ b/swh/scheduler/cli/task.py @@ -3,17 +3,21 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +from __future__ import annotations + # WARNING: do not import unnecessary things here to keep cli startup time under # control import locale import logging -from typing import TYPE_CHECKING, Any, Dict, Iterator, Optional +from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional import click from . import cli if TYPE_CHECKING: + import datetime + # importing swh.storage.interface triggers the load of 300+ modules, so... from swh.model.model import Origin from swh.storage.interface import StorageInterface @@ -561,7 +565,7 @@ help="Re spawn the selected tasks at this date", ) @click.pass_context -def respawn_tasks(ctx, task_ids, next_run): +def respawn_tasks(ctx, task_ids: List[str], next_run: datetime.datetime): """Respawn tasks. Respawn tasks given by their ids (see the 'task list' command to @@ -580,10 +584,12 @@ next_run = utcnow() output = [] + task_ids_int = [int(id_) for id_ in task_ids] + scheduler.set_status_tasks( - task_ids, status="next_run_not_scheduled", next_run=next_run + task_ids_int, status="next_run_not_scheduled", next_run=next_run ) - output.append("Respawn tasks %s\n" % (task_ids,)) + output.append("Respawn tasks %s\n" % (task_ids_int,)) click.echo("\n".join(output)) diff --git a/swh/scheduler/interface.py b/swh/scheduler/interface.py --- a/swh/scheduler/interface.py +++ b/swh/scheduler/interface.py @@ -94,7 +94,12 @@ ... @remote_api_endpoint("task/set_status") - def set_status_tasks(self, task_ids, status="disabled", next_run=None): + def set_status_tasks( + self, + task_ids: List[int], + status: str = "disabled", + next_run: Optional[datetime.datetime] = None, + ): """Set the tasks' status whose ids are listed. If given, also set the next_run date.