Page MenuHomeSoftware Heritage

D935.id2975.diff
No OneTemporary

D935.id2975.diff

diff --git a/swh/scheduler/api/client.py b/swh/scheduler/api/client.py
--- a/swh/scheduler/api/client.py
+++ b/swh/scheduler/api/client.py
@@ -28,9 +28,9 @@
def close_connection(self):
return self.post('close_connection', {})
- def set_status_tasks(self, task_ids, status='disabled'):
- return self.post('set_status_tasks', {'task_ids': task_ids,
- 'status': status})
+ def set_status_tasks(self, task_ids, status='disabled', next_run=None):
+ return self.post('set_status_tasks', dict(
+ task_ids=task_ids, status=status, next_run=next_run))
def create_task_type(self, task_type):
return self.post('create_task_type', {'task_type': task_type})
diff --git a/swh/scheduler/backend.py b/swh/scheduler/backend.py
--- a/swh/scheduler/backend.py
+++ b/swh/scheduler/backend.py
@@ -291,13 +291,23 @@
return cursor.fetchall()
@autocommit
- def set_status_tasks(self, task_ids, status='disabled', cursor=None):
- """Set the tasks' status whose ids are listed."""
+ def set_status_tasks(self, task_ids,
+ status='disabled', next_run=None, cursor=None):
+ """Set the tasks' status whose ids are listed.
+
+ If given, also set the next_run date.
+ """
if not task_ids:
return
- query = "UPDATE task SET status = %s WHERE id IN %s"
- cursor.execute(query, (status, tuple(task_ids),))
- return None
+ query = ["UPDATE task SET status = %s"]
+ args = [status]
+ if next_run:
+ query.append(', next_run = %s')
+ args.append(next_run)
+ query.append(" WHERE id IN %s")
+ args.append(tuple(task_ids))
+
+ cursor.execute(''.join(query), args)
@autocommit
def disable_tasks(self, task_ids, cursor=None):
diff --git a/swh/scheduler/cli.py b/swh/scheduler/cli.py
--- a/swh/scheduler/cli.py
+++ b/swh/scheduler/cli.py
@@ -342,6 +342,37 @@
click.echo('\n'.join(output))
+@task.command('respawn')
+@click.argument('task-ids', required=True, nargs=-1)
+@click.option('--next-run', '-n', required=False, type=DATETIME,
+ default=None,
+ help='Re spawn the selected tasks at tis date')
+@click.pass_context
+def respawn_tasks(ctx, task_ids, next_run):
+ """Respawn tasks.
+
+ Respawn the give tasks (by their id, see the 'task list' command to
+ find task ids) at the given date (immediately by default).
+
+ Eg.
+
+ swh-scheduler task respawn 1 3 12
+ """
+ scheduler = ctx.obj['scheduler']
+ if not scheduler:
+ raise ValueError('Scheduler class (local/remote) must be instantiated')
+ if next_run is None:
+ next_run = arrow.utcnow()
+ output = []
+
+ scheduler.set_status_tasks(
+ task_ids, status='next_run_not_scheduled', next_run=next_run)
+ output.append('Respawn tasks %s\n' % (
+ task_ids))
+
+ click.echo('\n'.join(output))
+
+
@task.command('archive')
@click.option('--before', '-b', default=None,
help='''Task whose ended date is anterior will be archived.

File Metadata

Mime Type
text/plain
Expires
Jul 3 2025, 6:12 PM (4 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3229262

Event Timeline