Skip to content

Commit

Permalink
fix: launch rq workers using CLI to init sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Nov 14, 2024
1 parent bcc0e9b commit 2c7d0d7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ services:
workers:
<<: *service-base
environment: *service-base-env
command: rq worker --url redis://${REDIS_HOST:-redis}:6379 off-exports-high off-exports-low
command: python3 -m openfoodfacts_exports run-worker off-exports-high off-exports-low
mem_limit: 4g
depends_on:
- redis
Expand Down
13 changes: 13 additions & 0 deletions openfoodfacts_exports/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@app.command()
def run_scheduler():
"""Run the scheduler, that will launch the export jobs once a day."""
from openfoodfacts.utils import get_logger

from openfoodfacts_exports.scheduler import run
Expand All @@ -15,6 +16,18 @@ def run_scheduler():
run()


@app.command()
def run_worker(queues: list[str], burst: bool = False):
"""Run a worker for the given queues."""
from openfoodfacts.utils import get_logger

from openfoodfacts_exports.workers.main import run

# configure root logger
get_logger()
run(queues, burst)


@app.command()
def launch_export(flavor: Flavor) -> None:
"""Launch an export job for a given flavor."""
Expand Down
18 changes: 18 additions & 0 deletions openfoodfacts_exports/workers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sys

from rq import Worker

from openfoodfacts_exports.utils import init_sentry

from .redis import redis_conn

init_sentry()


def run(queues: list[str], burst: bool = False):
try:
w = Worker(queues=queues, connection=redis_conn)
w.work(logging_level="INFO", burst=burst)
except ConnectionError as e:
print(e)
sys.exit(1)

0 comments on commit 2c7d0d7

Please sign in to comment.