Skip to content
Snippets Groups Projects
Verified Commit 05312da8 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Fix Celery task registration with import commands

parent 1029ab3b
No related branches found
No related tags found
1 merge request!108Resolve "Celery tasks are not working properly"
Pipeline #49596 passed with warnings
......@@ -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
-------------------
......
......@@ -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__()}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment