Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/core/lister_base.py
Show First 20 Lines • Show All 385 Lines • ▼ Show 20 Lines | def task_dict(self, origin_type, origin_url, **kwargs): | ||||
Args: | Args: | ||||
origin_type (string) | origin_type (string) | ||||
origin_url (string) | origin_url (string) | ||||
Returns: | Returns: | ||||
the same information in a different form | the same information in a different form | ||||
""" | """ | ||||
_type = 'load-%s' % origin_type | _type = 'load-%s' % origin_type | ||||
_policy = 'recurring' | _policy = kwargs.get('policy', 'recurring') | ||||
return utils.create_task_dict(_type, _policy, origin_url) | priority = kwargs.get('priority') | ||||
kw = {'priority': priority} if priority else {} | |||||
return utils.create_task_dict(_type, _policy, origin_url, **kw) | |||||
def string_pattern_check(self, a, b, c=None): | def string_pattern_check(self, a, b, c=None): | ||||
"""When comparing indexable types in is_within_bounds, complex strings | """When comparing indexable types in is_within_bounds, complex strings | ||||
may not be allowed to differ in basic structure. If they do, it | may not be allowed to differ in basic structure. If they do, it | ||||
could be a sign of not understanding the data well. For instance, | could be a sign of not understanding the data well. For instance, | ||||
an ISO 8601 time string cannot be compared against its urlencoded | an ISO 8601 time string cannot be compared against its urlencoded | ||||
equivalent, but this is an easy mistake to accidentally make. This | equivalent, but this is an easy mistake to accidentally make. This | ||||
method acts as a friendly sanity check. | method acts as a friendly sanity check. | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | def schedule_missing_tasks(self, models_list, injected_repos): | ||||
return '%s-%s' % ( | return '%s-%s' % ( | ||||
m['type'], | m['type'], | ||||
json.dumps(m['arguments'], sort_keys=True) | json.dumps(m['arguments'], sort_keys=True) | ||||
) | ) | ||||
for m in models_list: | for m in models_list: | ||||
ir = injected_repos[m['uid']] | ir = injected_repos[m['uid']] | ||||
if not ir.task_id: | if not ir.task_id: | ||||
# Patching the model instance to add the policy/priority task | |||||
# scheduling | |||||
if 'policy' in self.config: | |||||
m['policy'] = self.config['policy'] | |||||
if 'priority' in self.config: | |||||
m['priority'] = self.config['priority'] | |||||
task_dict = self.task_dict(**m) | task_dict = self.task_dict(**m) | ||||
tasks[_task_key(task_dict)] = (ir, m, task_dict) | tasks[_task_key(task_dict)] = (ir, m, task_dict) | ||||
new_tasks = self.scheduler.create_tasks( | new_tasks = self.scheduler.create_tasks( | ||||
(task_dicts for (_, _, task_dicts) in tasks.values())) | (task_dicts for (_, _, task_dicts) in tasks.values())) | ||||
for task in new_tasks: | for task in new_tasks: | ||||
ir, m, _ = tasks[_task_key(task)] | ir, m, _ = tasks[_task_key(task)] | ||||
ir.task_id = task['id'] | ir.task_id = task['id'] | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |