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):