summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-11 19:52:54 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-09-11 19:52:54 +0200
commitc9ffe94572f9853848e6aa3bad4246ea15e21319 (patch)
treea5211b5a7698b47c2b9197b294f1549612a811de
parentf9741ae70536851f24318e09bce51086de6bc130 (diff)
downloadIshtar-c9ffe94572f9853848e6aa3bad4246ea15e21319.tar.bz2
Ishtar-c9ffe94572f9853848e6aa3bad4246ea15e21319.zip
Make archive import/export tasks serializable for Celery tasks
-rw-r--r--ishtar_common/admin.py8
-rw-r--r--ishtar_common/tasks.py13
2 files changed, 15 insertions, 6 deletions
diff --git a/ishtar_common/admin.py b/ishtar_common/admin.py
index bd068890e..98f7c2663 100644
--- a/ishtar_common/admin.py
+++ b/ishtar_common/admin.py
@@ -1428,8 +1428,8 @@ def launch_export_action(modeladmin, request, queryset):
export_task.save()
if not settings.USE_BACKGROUND_TASK:
- return launch_export(export_task)
- return launch_export.delay(export_task)
+ return launch_export(export_task.pk)
+ return launch_export.delay(export_task.pk)
launch_export_action.short_description = _("Launch export")
@@ -1474,8 +1474,8 @@ def launch_import_action(modeladmin, request, queryset):
import_task.save()
if not settings.USE_BACKGROUND_TASK:
- return launch_import(import_task)
- return launch_import.delay(import_task)
+ return launch_import(import_task.pk)
+ return launch_import.delay(import_task.pk)
launch_import_action.short_description = _("Launch import")
diff --git a/ishtar_common/tasks.py b/ishtar_common/tasks.py
index 07286ad76..eec97d68a 100644
--- a/ishtar_common/tasks.py
+++ b/ishtar_common/tasks.py
@@ -31,6 +31,7 @@ from ishtar_common.models import Town, Department
from ishtar_common.utils import task
from ishtar_common.serializers import full_serialization, restore_serialized
+from ishtar_common.models import ImportTask, ExportTask
from archaeological_operations.models import Operation, ArchaeologicalSite
from archaeological_context_records.models import ContextRecord
from archaeological_finds.models import Find
@@ -43,7 +44,11 @@ from archaeological_warehouse.views import get_warehouse
@task()
-def launch_import(import_task):
+def launch_import(import_task_id):
+ try:
+ import_task = ImportTask.objects.get(pk=import_task_id)
+ except ImportTask.DoesNotExist:
+ return
if import_task.state != 'S':
return
import_task.launch_date = datetime.datetime.now()
@@ -60,7 +65,11 @@ def launch_import(import_task):
@task()
-def launch_export(export_task):
+def launch_export(export_task_id):
+ try:
+ export_task = ExportTask.objects.get(pk=export_task_id)
+ except ExportTask.DoesNotExist:
+ return
if export_task.state != 'S':
return
export_task.launch_date = datetime.datetime.now()