adamant-magazine-16751
10/04/2022, 10:36 AMcelery -A path.to.module inspect ping. The problem here is that celery is a part of the .pex file, and it is unclear how to find it and execute it.
One way to just find the binary would be to package the pexes in execution_mode="venv" , set PEX_ROOT to a known location and then to use source $PEX_ROOT/venvs/s/*/venv/bin/activate This way I can reach the binary. But the problem remains, because I can't reach the module I need (it is in user code). I suppose I'd also need to set up PYTHONPATH.
Another way to reach the binary would be to just install celery itself separately in the system python distribution, but I would still need to reach the user code binary.
Both the solutions seem like a lot of hackery and I'm not even sure if it's possible to pull any of them off.
Is there an easier way to achieve this - accessing venv binaries without running the pex file itself? Or maybe you can override the entrypoint when running venv. Or maybe there is a better way to package docker images? Any help would be much appreciatedadamant-magazine-16751
10/04/2022, 11:42 AMscript in pex_binary is already set to celery so I can just run the pex itself with two different sets of arguments. However the problem would remain if I needed to run two different binariesadamant-magazine-16751
10/04/2022, 11:46 AMscript to celery and needing to run anything else (can't think of any use case right now, but this could be anything that executes as a command like uwsgi or gunicorn )enough-analyst-54434
10/04/2022, 1:33 PM/myapp. Running /myapp/pex runs the PEX entry point, but you can also run any of the /myapp/bin/<console script> scripts the distributions in your PEX provide.enough-analyst-54434
10/04/2022, 1:34 PM/myapp/bin to PATH.enough-analyst-54434
10/04/2022, 1:36 PMadamant-magazine-16751
10/04/2022, 1:37 PMenough-analyst-54434
10/04/2022, 1:42 PMbusybox-alike: https://pypi.org/project/conscript/adamant-magazine-16751
10/04/2022, 3:35 PMscript field set in the srcs pex. I end up with this error though pex.pex_builder.PEXBuilder.InvalidExecutableSpecification: Could not find script 'celery' in any distribution within PEX! It is reasonable, I excluded the requirements, but I know it will be there in the final Docker image. If I leave the script field only in the deps pex, it gets overwritten and the entrypoint ends up being python. Is there any way around it or do I have to resort to the first configuration with multi-stage build but single pex?enough-analyst-54434
10/04/2022, 4:01 PMpex_binary targets forming the split; then in the docker image set PEX_SCRIPT (which corresponds to pex_binary.script) or PEX_MODULE (which corresponds to pex_binary.entry_point). I personally don't like this at all, I'd rather have a pex_binary target in my BUILD that I can test and know the final PEX in the Docker image will work the same as. A bit too many moving parts for my taste - but it should work.enough-analyst-54434
10/04/2022, 4:02 PMpex --help-variables or see here: https://pex.readthedocs.io/en/v2.1.107/api/vars.htmladamant-magazine-16751
10/04/2022, 4:04 PMbrash-glass-61350
05/03/2024, 8:54 AM# tasks.py
from celery import Celery
app = Celery('tasks', broker='<pyamqp://guest@localhost//>')
@app.task
def add(x, y):
return x + y
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",
)
I package with pants package but when I call:
celery_app.pex/__main__.py -A tasks worker
I get:
Unable to load celery application.
The module tasks was not found.
What am I missing?