I'm trying to use celery with pants, but I'm runni...
# general
b
I'm trying to use celery with pants, but I'm running into some issues. Here is the example from the celery docs: https://docs.celeryq.dev/en/stable/getting-started/first-steps-with-celery.html
Copy code
# tasks.py
from celery import Celery

app = Celery('tasks', broker='<pyamqp://guest@localhost//>')

@app.task
def add(x, y):
    return x + y
Copy code
python_source(
    name="tasks",
    source="tasks.py",
    dependencies=[
        "third_party:requirements#celery",
    ],
)

pex_binary(
    name="celery_app",
    script="celery",
    dependencies=[":tasks"],
    layout="packed",
    execution_mode="venv",
)
One is supposed to call celery as follows:
celery -A tasks worker
. Setting
script="celery"
on the
pex_binary
definition takes care of that. I package with
pants package
but when I call:
Copy code
celery_app.pex/__main__.py -A tasks worker
I get:
Copy code
Unable to load celery application.
The module tasks was not found.
What am I missing? How do I tell it to load
tasks.py
?
b
Sorry for the trouble. A good way to start debugging this sort of issue is to confirm the contents of the packaged pex: does it contain the necessary files? If so, where are they? (They may not have the import path you’re expecting)
b
Hi! I got this to run. Your hint helped me solve it. Inspecting the contents of the pex I could find the name