Differential D4830 Diff 17478 swh/web/common/migrations/0003_saveoriginrequest_loading_task_status.py
Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/migrations/0003_saveoriginrequest_loading_task_status.py
Show All 12 Lines | |||||
def _remove_archived_tasks_with_no_saved_status(apps, schema_editor): | def _remove_archived_tasks_with_no_saved_status(apps, schema_editor): | ||||
""" | """ | ||||
Scheduler tasks are archived on a regular basis so their completion | Scheduler tasks are archived on a regular basis so their completion | ||||
state could not be known anymore as previous to this migration, | state could not be known anymore as previous to this migration, | ||||
the loading task status was not stored in the database. | the loading task status was not stored in the database. | ||||
So remove the rows associated to already archived tasks as | So remove the rows associated to already archived tasks as | ||||
the loading status can not be retrieved anymore. | the loading status can not be retrieved anymore. | ||||
""" | """ | ||||
SaveOriginRequest = apps.get_model("swh.web.common", "SaveOriginRequest") | SaveOriginRequest = apps.get_model("swh_web_common", "SaveOriginRequest") | ||||
no_saved_status_tasks = [] | no_saved_status_tasks = [] | ||||
for sor in SaveOriginRequest.objects.all(): | for sor in SaveOriginRequest.objects.all(): | ||||
tasks = scheduler().get_tasks([sor.loading_task_id]) | tasks = scheduler().get_tasks([sor.loading_task_id]) | ||||
if not tasks: | if not tasks: | ||||
no_saved_status_tasks.append(sor.loading_task_id) | no_saved_status_tasks.append(sor.loading_task_id) | ||||
SaveOriginRequest.objects.filter(loading_task_id__in=no_saved_status_tasks).delete() | SaveOriginRequest.objects.filter(loading_task_id__in=no_saved_status_tasks).delete() | ||||
class Migration(migrations.Migration): | class Migration(migrations.Migration): | ||||
dependencies = [ | dependencies = [ | ||||
("swh.web.common", "0002_saveoriginrequest_visit_date"), | ("swh_web_common", "0002_saveoriginrequest_visit_date"), | ||||
] | ] | ||||
operations = [ | operations = [ | ||||
migrations.AddField( | migrations.AddField( | ||||
model_name="saveoriginrequest", | model_name="saveoriginrequest", | ||||
name="loading_task_status", | name="loading_task_status", | ||||
field=models.TextField( | field=models.TextField( | ||||
choices=[ | choices=[ | ||||
Show All 11 Lines |