Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/cli/admin.py
Show First 20 Lines • Show All 241 Lines • ▼ Show 20 Lines | from swh.deposit.config import ( | ||||
DEPOSIT_STATUS_VERIFIED, | DEPOSIT_STATUS_VERIFIED, | ||||
APIConfig, | APIConfig, | ||||
) | ) | ||||
from swh.deposit.models import Deposit | from swh.deposit.models import Deposit | ||||
try: | try: | ||||
deposit = Deposit.objects.get(pk=deposit_id) | deposit = Deposit.objects.get(pk=deposit_id) | ||||
except Deposit.DoesNotExist: | except Deposit.DoesNotExist: | ||||
click.echo("Deposit %s does not exist." % deposit_id) | click.echo(f"Deposit {deposit_id} does not exist.") | ||||
ctx.exit(1) | ctx.exit(1) | ||||
# Check the deposit is in a reasonable state | # Check the deposit is in a reasonable state | ||||
accepted_statuses = [DEPOSIT_STATUS_LOAD_SUCCESS, DEPOSIT_STATUS_LOAD_FAILURE] | accepted_statuses = [DEPOSIT_STATUS_LOAD_SUCCESS, DEPOSIT_STATUS_LOAD_FAILURE] | ||||
if deposit.status == DEPOSIT_STATUS_VERIFIED: | if deposit.status == DEPOSIT_STATUS_VERIFIED: | ||||
click.echo("Deposit %s's status already set for rescheduling." % (deposit_id)) | click.echo(f"Deposit {deposit_id} already set for rescheduling.") | ||||
ctx.exit(0) | ctx.exit(0) | ||||
if deposit.status not in accepted_statuses: | if deposit.status not in accepted_statuses: | ||||
click.echo( | click.echo( | ||||
"Deposit %s's status be one of %s." | f"Deposit {deposit_id} cannot be rescheduled (status: {deposit.status}).\n" | ||||
% (deposit_id, ", ".join(accepted_statuses)) | "Rescheduling deposit is only accepted for deposit with status: " | ||||
f"{', '.join(accepted_statuses)}." | |||||
) | ) | ||||
ctx.exit(1) | ctx.exit(1) | ||||
task_id = deposit.load_task_id | task_id = deposit.load_task_id | ||||
if not task_id: | if not task_id: | ||||
click.echo( | click.echo( | ||||
"Deposit %s cannot be rescheduled. It misses the " | f"Deposit {deposit_id} cannot be rescheduled. It misses the " | ||||
"associated task." % deposit_id | "associated scheduler task id (field load_task_id)." | ||||
) | ) | ||||
ctx.exit(1) | ctx.exit(1) | ||||
# Reset the deposit's state | # Reset the deposit's state | ||||
deposit.swhid = None | deposit.swhid = None | ||||
deposit.swhid_context = None | deposit.swhid_context = None | ||||
deposit.status = DEPOSIT_STATUS_VERIFIED | deposit.status = DEPOSIT_STATUS_VERIFIED | ||||
deposit.save() | deposit.save() | ||||
# Trigger back the deposit | # Schedule back the deposit loading task | ||||
scheduler = APIConfig().scheduler | scheduler = APIConfig().scheduler | ||||
scheduler.set_status_tasks( | scheduler.set_status_tasks( | ||||
[task_id], status="next_run_not_scheduled", next_run=datetime.now() | [task_id], status="next_run_not_scheduled", next_run=datetime.now() | ||||
) | ) |