Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/backend.py
Show First 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | def create_task_type(self, task_type, cursor=None): | ||||
- max_interval (datetime.timedelta): the maximum interval | - max_interval (datetime.timedelta): the maximum interval | ||||
between two task runs | between two task runs | ||||
- backoff_factor (float): the factor by which the interval | - backoff_factor (float): the factor by which the interval | ||||
changes at each run | changes at each run | ||||
- max_queue_length (int): the maximum length of the task queue | - max_queue_length (int): the maximum length of the task queue | ||||
for this task type | for this task type | ||||
""" | """ | ||||
keys = [key for key in self.task_type_keys if key in task_type] | |||||
query = self._format_query( | query = self._format_query( | ||||
"""insert into task_type ({keys}) values ({placeholders})""", | """insert into task_type ({keys}) values ({placeholders})""", | ||||
self.task_type_keys, | keys) | ||||
ardumont: Isn't it better to create the list of keys to use once and reuse it in both places? | |||||
Done Inline ActionsI was expecting someone to complain about it ;-) douardda: I was expecting someone to complain about it ;-) | |||||
) | cursor.execute(query, [task_type[key] for key in keys]) | ||||
cursor.execute(query, [task_type[key] for key in self.task_type_keys]) | |||||
@autocommit | @autocommit | ||||
def get_task_type(self, task_type_name, cursor=None): | def get_task_type(self, task_type_name, cursor=None): | ||||
"""Retrieve the task type with id task_type_name""" | """Retrieve the task type with id task_type_name""" | ||||
query = self._format_query( | query = self._format_query( | ||||
"select {keys} from task_type where type=%s", | "select {keys} from task_type where type=%s", | ||||
self.task_type_keys, | self.task_type_keys, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 291 Lines • Show Last 20 Lines |
Isn't it better to create the list of keys to use once and reuse it in both places?