#!/command/with-contenv bash

set -o errexit
set -o nounset
set -o pipefail
shopt -s inherit_errexit

ROMM_LOG_TAG="rq-streaming-worker"
# shellcheck source=SCRIPTDIR/../../scripts/lib.sh
source /etc/s6-overlay/scripts/lib.sh

record_process_group

if ! PYTHONPATH="/backend:${PYTHONPATH-}" python3 -c "
import sys
from config.config_manager import config_manager
sys.exit(0 if config_manager.get_config().STREAMING_ENABLED else 1)
" >/dev/null 2>&1; then
	debug_log "Streaming is disabled in config.yml, not starting the streaming worker"
	disable_service
fi

# Streaming teardowns get a worker of their own, see STREAMING_QUEUE_NAME. It
# preloads the reaper, which runs every minute when streaming is on.
info_log "Starting RQ streaming worker"
exec_rq_worker PreloadingWorker streaming
