Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cyclic Dependencies #3474

Closed
richburdon opened this issue Sep 26, 2016 · 3 comments
Closed

Cyclic Dependencies #3474

richburdon opened this issue Sep 26, 2016 · 3 comments

Comments

@richburdon
Copy link

richburdon commented Sep 26, 2016

Suppose I have two components: Frontend and Backend and the Celery Worker as the Backend.

[backend.py]

app = Celery(tasks="tasks")

[tasks.py]

import backend

@app.task()
def my_task():
    complex_logic_that_depends_on_secure_and_complicated_modules()

[frontend.py]

import tasks

app = Flask()

@app.route('/work')
def work():
    tasks.my_task.delay()

app.start()

It seems counter-intuitive to me that the "caller" (frontend.py) should need to depend on the implementation details (and dependent modules) of the task. I'd like to decouple them so that changes to the Backend logic don't require a redeploy of the Frontend.

Is there any way around this? I've tried having the tasks depend on current_app, but: a) this is discouraged in the docs; b) it leads to complex import dependencies (i.e., the frontend's app instance has to be defined before any tasks are imported -- otherwise current_app refers to a "default" instance). Also, using DI makes the issue more complex (since the Celery instance has to be injected).

@kindule
Copy link

kindule commented Sep 26, 2016

@richburdon
Copy link
Author

richburdon commented Sep 26, 2016

@kindule
Copy link

kindule commented Sep 27, 2016

I'm glad to help :)
Can you close the issue as we already get the answer?

@auvipy auvipy closed this as completed Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants