Skip to content
Snippets Groups Projects
Commit 557346c7 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch '37-celery-tasks-are-not-working-properly' into 'master'

Resolve "Celery tasks are not working properly"

Closes #37

See merge request !108
parents 1029ab3b 05312da8
No related branches found
No related tags found
1 merge request!108Resolve "Celery tasks are not working properly"
Pipeline #49669 failed
...@@ -26,6 +26,7 @@ Fixed ...@@ -26,6 +26,7 @@ Fixed
* Import failed if there were classes without class teachers. * Import failed if there were classes without class teachers.
* Management command ``move_dates_for_testing`` throwed misleading errors. * Management command ``move_dates_for_testing`` throwed misleading errors.
* Events weren't always deleted due to wrong date filters. * 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 `2.0`_ - 2021-10-30
------------------- -------------------
......
...@@ -32,7 +32,7 @@ class ImportCommand: ...@@ -32,7 +32,7 @@ class ImportCommand:
if background: if background:
from .tasks import TASKS from .tasks import TASKS
task = TASKS[cls] task = TASKS[cls.task_name]
task.delay() task.delay()
else: else:
_untis_import_mysql(cls.get_terms()) _untis_import_mysql(cls.get_terms())
...@@ -90,3 +90,4 @@ class CurrentFutureImportCommand(ImportCommand): ...@@ -90,3 +90,4 @@ class CurrentFutureImportCommand(ImportCommand):
COMMANDS_BY_NAME = {c.name: c for c in ImportCommand.__subclasses__()} 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 aleksis.core.celery import app
from .commands import ImportCommand from .commands import COMMANDS_BY_TASK_NAME, ImportCommand
TASKS = {} TASKS = {}
for import_command in ImportCommand.__subclasses__(): for import_command in ImportCommand.__subclasses__():
@app.task(name=import_command.task_name) @app.task(name=import_command.task_name, bind=True)
def _task(): def _task(self):
import_command = COMMANDS_BY_TASK_NAME[self.name]
import_command.run() 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