diff --git a/CHANGELOG.rst b/CHANGELOG.rst index befdb51d1320934c665b53be3beb4a0d49abe494..53af44f4bac431c05d98a9ddc0099f677ac615f1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -26,6 +26,7 @@ Fixed * Import failed if there were classes without class teachers. * Management command ``move_dates_for_testing`` throwed misleading errors. * Events weren't always deleted due to wrong date filters. +* Celery tasks always ran the last import command and not the supposed one. `2.0`_ - 2021-10-30 ------------------- diff --git a/aleksis/apps/untis/commands.py b/aleksis/apps/untis/commands.py index 6866cc6f340eadc3b76cfcabe6b0b19dd2f583b9..ce6b17a86b07347468f9a737da16a0868fe4cb48 100644 --- a/aleksis/apps/untis/commands.py +++ b/aleksis/apps/untis/commands.py @@ -32,7 +32,7 @@ class ImportCommand: if background: from .tasks import TASKS - task = TASKS[cls] + task = TASKS[cls.task_name] task.delay() else: _untis_import_mysql(cls.get_terms()) @@ -90,3 +90,4 @@ class CurrentFutureImportCommand(ImportCommand): COMMANDS_BY_NAME = {c.name: c for c in ImportCommand.__subclasses__()} +COMMANDS_BY_TASK_NAME = {c.task_name: c for c in ImportCommand.__subclasses__()} diff --git a/aleksis/apps/untis/tasks.py b/aleksis/apps/untis/tasks.py index c7aaa854d7dd604b5b9e7712d584954b0de24ea4..6da6405c5ad00f37dd90a046bf23121993dceb94 100644 --- a/aleksis/apps/untis/tasks.py +++ b/aleksis/apps/untis/tasks.py @@ -1,12 +1,13 @@ from aleksis.core.celery import app -from .commands import ImportCommand +from .commands import COMMANDS_BY_TASK_NAME, ImportCommand TASKS = {} for import_command in ImportCommand.__subclasses__(): - @app.task(name=import_command.task_name) - def _task(): + @app.task(name=import_command.task_name, bind=True) + def _task(self): + import_command = COMMANDS_BY_TASK_NAME[self.name] import_command.run() - TASKS[import_command] = _task + TASKS[import_command.task_name] = _task