Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/backend.py
Show First 20 Lines • Show All 488 Lines • ▼ Show 20 Lines | def create_tasks(self, tasks, policy="recurring", db=None, cur=None): | ||||
query = format_query( | query = format_query( | ||||
"select {keys} from swh_scheduler_create_tasks_from_temp()", self.task_keys, | "select {keys} from swh_scheduler_create_tasks_from_temp()", self.task_keys, | ||||
) | ) | ||||
cur.execute(query) | cur.execute(query) | ||||
return cur.fetchall() | return cur.fetchall() | ||||
@db_transaction() | @db_transaction() | ||||
def set_status_tasks( | 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. | """Set the tasks' status whose ids are listed. | ||||
If given, also set the next_run date. | If given, also set the next_run date. | ||||
""" | """ | ||||
if not task_ids: | if not task_ids: | ||||
return | return | ||||
query = ["UPDATE task SET status = %s"] | query = ["UPDATE task SET status = %s"] | ||||
args = [status] | args: List[Any] = [status] | ||||
if next_run: | if next_run: | ||||
query.append(", next_run = %s") | query.append(", next_run = %s") | ||||
args.append(next_run) | args.append(next_run) | ||||
query.append(" WHERE id IN %s") | query.append(" WHERE id IN %s") | ||||
args.append(tuple(task_ids)) | args.append(tuple(task_ids)) | ||||
cur.execute("".join(query), args) | cur.execute("".join(query), args) | ||||
▲ Show 20 Lines • Show All 525 Lines • Show Last 20 Lines |