Page MenuHomeSoftware Heritage

D1446.diff
No OneTemporary

D1446.diff

diff --git a/swh/deposit/migrations/0016_auto_20190507_1408.py b/swh/deposit/migrations/0016_auto_20190507_1408.py
new file mode 100644
--- /dev/null
+++ b/swh/deposit/migrations/0016_auto_20190507_1408.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.18 on 2019-05-07 14:08
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('deposit', '0015_depositrequest_typemigration'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='deposit',
+ name='check_task_id',
+ field=models.TextField(blank=True, null=True, verbose_name="Scheduler's associated checking task id"),
+ ),
+ migrations.AddField(
+ model_name='deposit',
+ name='load_task_id',
+ field=models.TextField(blank=True, null=True, verbose_name="Scheduler's associated loading task id"),
+ ),
+ ]
diff --git a/swh/deposit/models.py b/swh/deposit/models.py
--- a/swh/deposit/models.py
+++ b/swh/deposit/models.py
@@ -122,6 +122,14 @@
status_detail = JSONField(null=True)
# deposit can have one parent
parent = models.ForeignKey('self', null=True)
+ check_task_id = models.TextField(
+ blank=True, null=True,
+ verbose_name="Scheduler's associated checking task id"
+ )
+ load_task_id = models.TextField(
+ blank=True, null=True,
+ verbose_name="Scheduler's associated loading task id"
+ )
class Meta:
db_table = 'deposit'
diff --git a/swh/deposit/signals.py b/swh/deposit/signals.py
--- a/swh/deposit/signals.py
+++ b/swh/deposit/signals.py
@@ -21,6 +21,22 @@
from .config import DEPOSIT_STATUS_DEPOSITED
+def schedule_task(scheduler, task):
+ """Schedule the task and return its identifier
+
+ Args:
+ task (dict): Task to schedule
+
+ Returns:
+ The task identifier
+
+ """
+ tasks = scheduler.create_tasks([task])
+ if tasks:
+ created_task = tasks[0]
+ return created_task['id']
+
+
@receiver(post_save, sender=Deposit)
def post_deposit_save(sender, instance, created, raw, using,
update_fields, **kwargs):
@@ -58,15 +74,25 @@
args = [instance.collection.name, instance.id]
- if instance.status == DEPOSIT_STATUS_DEPOSITED:
- # schedule archive check
+ # In the following, we are checking the instance.*task_id are not already
+ # populated because the `instance.save()` call will also trigger a call to
+ # that very function.
+
+ if (instance.status == DEPOSIT_STATUS_DEPOSITED and
+ not instance.check_task_id):
+ # schedule deposit's checks
from swh.deposit.config import PRIVATE_CHECK_DEPOSIT
check_url = reverse(PRIVATE_CHECK_DEPOSIT, args=args)
task = create_oneshot_task_dict(
'swh-deposit-archive-checks',
deposit_check_url=check_url)
- else: # instance.status == DEPOSIT_STATUS_VERIFIED:
- # schedule loading
+ check_task_id = schedule_task(default_config.scheduler, task)
+ instance.check_task_id = check_task_id
+ instance.save()
+
+ elif (instance.status == DEPOSIT_STATUS_VERIFIED and
+ not instance.load_task_id):
+ # schedule deposit loading
from swh.deposit.config import PRIVATE_GET_RAW_CONTENT
from swh.deposit.config import PRIVATE_GET_DEPOSIT_METADATA
from swh.deposit.config import PRIVATE_PUT_DEPOSIT
@@ -80,4 +106,6 @@
deposit_meta_url=meta_url,
deposit_update_url=update_url)
- default_config.scheduler.create_tasks([task])
+ load_task_id = schedule_task(default_config.scheduler, task)
+ instance.load_task_id = load_task_id
+ instance.save()

File Metadata

Mime Type
text/plain
Expires
Sun, Aug 17, 11:00 PM (1 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3224635

Event Timeline