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

feat: start celery worker programmatically #2988

Merged
merged 1 commit into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \
USER ${UID}:${GID}
WORKDIR /app

CMD ["/usr/local/bin/celery", "worker", \
"--app=libretime_worker.tasks:worker", \
"--config=libretime_worker.config", \
"--beat", \
"--time-limit=1800", \
"--concurrency=1", \
"--loglevel=info"]

CMD ["/usr/local/bin/libretime-worker"]
ARG LIBRETIME_VERSION
ENV LIBRETIME_VERSION=$LIBRETIME_VERSION

Expand Down
9 changes: 1 addition & 8 deletions worker/install/systemd/libretime-worker.service
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ Environment=LIBRETIME_CONFIG_FILEPATH=@@CONFIG_FILEPATH@@
Environment=LIBRETIME_LOG_FILEPATH=@@LOG_DIR@@/worker.log
WorkingDirectory=@@WORKING_DIR@@/worker

ExecStart=/usr/bin/sh -c '@@VENV_DIR@@/bin/celery worker \
--app=libretime_worker.tasks:worker \
--config=libretime_worker.config \
--beat \
--time-limit=1800 \
--concurrency=1 \
--loglevel=INFO \
--logfile=$LIBRETIME_LOG_FILEPATH'
ExecStart=/usr/local/bin/libretime-worker
Restart=always

User=libretime
Expand Down
28 changes: 28 additions & 0 deletions worker/libretime_worker/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from pathlib import Path
from typing import Optional

import click
from libretime_shared.cli import cli_logging_options
from libretime_shared.config import DEFAULT_ENV_PREFIX

from .config import __name__ as config_module
from .tasks import worker


@click.command(context_settings={"auto_envvar_prefix": DEFAULT_ENV_PREFIX})
@cli_logging_options()
def cli(log_level: str, log_filepath: Optional[Path]):
"""
Run celery.
"""
args = [
f"--config={config_module}",
"--beat",
"--time-limit=1800",
"--concurrency=1",
f"--loglevel={log_level}",
]
if log_filepath is not None:
args.append(f"--logfile={log_filepath}")

worker.worker_main(args)
5 changes: 5 additions & 0 deletions worker/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
},
license="MIT",
packages=find_packages(exclude=["*tests*", "*fixtures*"]),
entry_points={
"console_scripts": [
"libretime-worker=libretime_worker.main:cli",
]
},
python_requires=">=3.8",
install_requires=[
"celery==4.4.7",
Expand Down
Loading