feat(worker): load config using shared helpers

BREAKING CHANGE: The worker `RMQ_CONFIG_FILE` environement variable has
been renamed to `LIBRETIME_CONFIG_FILEPATH`. In addition the systemd
working directory for the worker has changed from `/srv/airtime` to
`/var/lib/libretime/worker`.
This commit is contained in:
jo 2022-02-22 20:03:31 +01:00 committed by Kyle Robbertze
parent d42615eb6a
commit 9b6d657fd6
7 changed files with 29 additions and 36 deletions

View file

@ -1,43 +0,0 @@
import os
from configobj import ConfigObj
from kombu import Exchange, Queue
# Get the broker string from airtime.conf
RMQ_CONFIG_SECTION = "rabbitmq"
def get_rmq_broker():
rmq_config = ConfigObj(os.environ["RMQ_CONFIG_FILE"])
rmq_settings = parse_rmq_config(rmq_config)
return "amqp://{username}:{password}@{host}:{port}/{vhost}".format(**rmq_settings)
def parse_rmq_config(rmq_config):
return {
"host": rmq_config[RMQ_CONFIG_SECTION]["host"],
"port": rmq_config[RMQ_CONFIG_SECTION]["port"],
"username": rmq_config[RMQ_CONFIG_SECTION]["user"],
"password": rmq_config[RMQ_CONFIG_SECTION]["password"],
"vhost": rmq_config[RMQ_CONFIG_SECTION]["vhost"],
}
# Celery amqp settings
BROKER_URL = get_rmq_broker()
CELERY_RESULT_BACKEND = "amqp" # Use RabbitMQ as the celery backend
CELERY_RESULT_PERSISTENT = True # Persist through a broker restart
CELERY_TASK_RESULT_EXPIRES = 900 # Expire task results after 15 minutes
CELERY_RESULT_EXCHANGE = "celeryresults" # Default exchange - needed due to php-celery
CELERY_QUEUES = (
Queue("podcast", exchange=Exchange("podcast"), routing_key="podcast"),
Queue(exchange=Exchange("celeryresults"), auto_delete=True),
)
CELERY_EVENT_QUEUE_EXPIRES = 900 # RabbitMQ x-expire after 15 minutes
# Celery task settings
CELERY_TASK_SERIALIZER = "json"
CELERY_RESULT_SERIALIZER = "json"
CELERY_ACCEPT_CONTENT = ["json"]
CELERY_TIMEZONE = "Europe/Berlin"
CELERY_ENABLE_UTC = True