on met à jour la tâche pour indiquer qu'elle est finie

This commit is contained in:
Jean-Marie Favreau 2023-12-23 11:35:57 +01:00
parent 5d3881721f
commit e52b9b0400

View File

@ -25,6 +25,17 @@ app.config_from_object("django.conf:settings", namespace="CELERY")
# Load task modules from all registered Django apps.
app.autodiscover_tasks()
def close_import_task(taskid, success, error_message):
from agenda_culturel.models import BatchImportation
task = BatchImportation.objects.get(pk=taskid)
task.status = BatchImportation.STATUS.SUCCESS if success else BatchImportation.STATUS.FAILED
fields = ["status"]
if not success:
task.error_message = error_message
fields.append("error_message")
task.save(update_fields=fields)
@app.task(bind=True)
def import_events_from_json(self, json, taskid):
@ -34,6 +45,12 @@ def import_events_from_json(self, json, taskid):
# TODO
success = True
error_message = ""
# finally, close task
close_import_task(taskid, success, error_message)
@app.task(bind=True)
def import_events_from_url(self, source, browsable_url, taskid):
@ -43,5 +60,12 @@ def import_events_from_url(self, source, browsable_url, taskid):
# TODO
success = True
error_message = ""
# finally, close task
close_import_task(taskid, success, error_message)
app.conf.timezone = "Europe/Paris"