fix: trigger legacy tasks manager every 5m (#2987)
### Description This ensures that when the LibreTime interface is not used for a long time, we still have the task manager run essential tasks for the schedule. Related to #2670
This commit is contained in:
parent
bcaa77ff3c
commit
7040d0e4bd
|
@ -189,6 +189,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
pip install --no-compile -r requirements.txt
|
pip install --no-compile -r requirements.txt
|
||||||
|
|
||||||
COPY --from=python-builder /build/shared/*.whl .
|
COPY --from=python-builder /build/shared/*.whl .
|
||||||
|
COPY --from=python-builder /build/api-client/*.whl .
|
||||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||||
pip install --no-compile *.whl && rm -Rf *.whl
|
pip install --no-compile *.whl && rm -Rf *.whl
|
||||||
|
|
||||||
|
@ -203,6 +204,7 @@ WORKDIR /app
|
||||||
CMD ["/usr/local/bin/celery", "worker", \
|
CMD ["/usr/local/bin/celery", "worker", \
|
||||||
"--app=libretime_worker.tasks:worker", \
|
"--app=libretime_worker.tasks:worker", \
|
||||||
"--config=libretime_worker.config", \
|
"--config=libretime_worker.config", \
|
||||||
|
"--beat", \
|
||||||
"--time-limit=1800", \
|
"--time-limit=1800", \
|
||||||
"--concurrency=1", \
|
"--concurrency=1", \
|
||||||
"--loglevel=info"]
|
"--loglevel=info"]
|
||||||
|
|
|
@ -214,3 +214,6 @@ class ApiClient:
|
||||||
|
|
||||||
def update_metadata_on_tunein(self):
|
def update_metadata_on_tunein(self):
|
||||||
self._base_client.update_metadata_on_tunein()
|
self._base_client.update_metadata_on_tunein()
|
||||||
|
|
||||||
|
def trigger_task_manager(self):
|
||||||
|
self._base_client.version()
|
||||||
|
|
|
@ -3,6 +3,7 @@ all: lint test
|
||||||
include ../tools/python.mk
|
include ../tools/python.mk
|
||||||
|
|
||||||
PIP_INSTALL := \
|
PIP_INSTALL := \
|
||||||
|
--editable ../api-client \
|
||||||
--editable ../shared \
|
--editable ../shared \
|
||||||
--editable .[dev,sentry]
|
--editable .[dev,sentry]
|
||||||
PYLINT_ARG := libretime_worker
|
PYLINT_ARG := libretime_worker
|
||||||
|
|
|
@ -25,6 +25,7 @@ WorkingDirectory=@@WORKING_DIR@@/worker
|
||||||
ExecStart=/usr/bin/sh -c '@@VENV_DIR@@/bin/celery worker \
|
ExecStart=/usr/bin/sh -c '@@VENV_DIR@@/bin/celery worker \
|
||||||
--app=libretime_worker.tasks:worker \
|
--app=libretime_worker.tasks:worker \
|
||||||
--config=libretime_worker.config \
|
--config=libretime_worker.config \
|
||||||
|
--beat \
|
||||||
--time-limit=1800 \
|
--time-limit=1800 \
|
||||||
--concurrency=1 \
|
--concurrency=1 \
|
||||||
--loglevel=INFO \
|
--loglevel=INFO \
|
||||||
|
|
|
@ -20,6 +20,7 @@ CELERY_RESULT_PERSISTENT = True # Persist through a broker restart
|
||||||
CELERY_TASK_RESULT_EXPIRES = 900 # Expire task results after 15 minutes
|
CELERY_TASK_RESULT_EXPIRES = 900 # Expire task results after 15 minutes
|
||||||
CELERY_RESULT_EXCHANGE = "celeryresults" # Default exchange - needed due to php-celery
|
CELERY_RESULT_EXCHANGE = "celeryresults" # Default exchange - needed due to php-celery
|
||||||
CELERY_QUEUES = (
|
CELERY_QUEUES = (
|
||||||
|
Queue("celery", exchange=Exchange("celery"), routing_key="celery"),
|
||||||
Queue("podcast", exchange=Exchange("podcast"), routing_key="podcast"),
|
Queue("podcast", exchange=Exchange("podcast"), routing_key="podcast"),
|
||||||
Queue(exchange=Exchange("celeryresults"), auto_delete=True),
|
Queue(exchange=Exchange("celeryresults"), auto_delete=True),
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,7 +9,9 @@ from urllib.parse import urlsplit
|
||||||
import mutagen
|
import mutagen
|
||||||
import requests
|
import requests
|
||||||
from celery import Celery, signals
|
from celery import Celery, signals
|
||||||
|
from celery.schedules import crontab
|
||||||
from celery.utils.log import get_task_logger
|
from celery.utils.log import get_task_logger
|
||||||
|
from libretime_api_client.v1 import ApiClient as LegacyClient
|
||||||
from mutagen import MutagenError
|
from mutagen import MutagenError
|
||||||
from requests import RequestException, Response
|
from requests import RequestException, Response
|
||||||
|
|
||||||
|
@ -19,6 +21,11 @@ from .config import config
|
||||||
worker = Celery()
|
worker = Celery()
|
||||||
logger = get_task_logger(__name__)
|
logger = get_task_logger(__name__)
|
||||||
|
|
||||||
|
legacy_client = LegacyClient(
|
||||||
|
base_url=config.general.public_url,
|
||||||
|
api_key=config.general.api_key,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@signals.worker_init.connect
|
@signals.worker_init.connect
|
||||||
def init_sentry(**_kwargs):
|
def init_sentry(**_kwargs):
|
||||||
|
@ -37,6 +44,22 @@ def init_sentry(**_kwargs):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
worker.conf.beat_schedule = {
|
||||||
|
"legacy-trigger-task-manager": {
|
||||||
|
"task": "libretime_worker.tasks.legacy_trigger_task_manager",
|
||||||
|
"schedule": crontab(minute="*/5"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@worker.task()
|
||||||
|
def legacy_trigger_task_manager():
|
||||||
|
"""
|
||||||
|
Trigger the legacy task manager to perform background tasks.
|
||||||
|
"""
|
||||||
|
legacy_client.trigger_task_manager()
|
||||||
|
|
||||||
|
|
||||||
@worker.task(name="podcast-download", acks_late=True)
|
@worker.task(name="podcast-download", acks_late=True)
|
||||||
def podcast_download(
|
def podcast_download(
|
||||||
episode_id: int,
|
episode_id: int,
|
||||||
|
|
Loading…
Reference in New Issue