mirror of
https://github.com/rommapp/romm.git
synced 2026-11-30 02:22:44 +01:00
review: guard the RQ worker PID file and comment it where it is written
Adds a test that start_rq_worker records $! instead of passing --pid, and moves the comment next to the line it explains. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -82,6 +82,19 @@ def test_gunicorn_outlives_nginx_upstream_idle_timeout() -> None:
|
||||
assert _init_script_keepalive() > NGINX_UPSTREAM_IDLE_TIMEOUT
|
||||
|
||||
|
||||
def test_init_script_records_the_rq_worker_pid_at_launch() -> None:
|
||||
match = re.search(
|
||||
r"^start_rq_worker\(\) \{\n(.*?)^\}", INIT_SCRIPT.read_text(), re.M | re.S
|
||||
)
|
||||
assert match, "could not read start_rq_worker from the init script"
|
||||
body = match.group(1)
|
||||
assert not re.search(r"^\s*--pid\b", body, re.M), (
|
||||
"RQ writes --pid only after importing the worker class, so the watchdog "
|
||||
"would start duplicate workers while a slow import runs"
|
||||
)
|
||||
assert re.search(r'^\s*echo "\$!" >"/tmp/\$\{name\}\.pid"$', body, re.M)
|
||||
|
||||
|
||||
def test_env_template_documents_the_same_keepalive_default() -> None:
|
||||
match = re.search(r"^WEB_SERVER_KEEPALIVE=(\d+)", ENV_TEMPLATE.read_text(), re.M)
|
||||
assert match, "env.template is missing WEB_SERVER_KEEPALIVE"
|
||||
|
||||
@@ -278,8 +278,6 @@ start_bin_rq_scan_worker() {
|
||||
# orphaned STARTED jobs and stale workers are still pruned promptly.
|
||||
# --with-scheduler releases delayed jobs, which is how the watcher's rescans
|
||||
# wait out their delay.
|
||||
# The PID is recorded here, not with --pid: RQ writes that file only after
|
||||
# importing the worker class, and the watchdog would start a duplicate meanwhile.
|
||||
start_rq_worker() {
|
||||
local name="$1"
|
||||
shift
|
||||
@@ -296,6 +294,8 @@ start_rq_worker() {
|
||||
--logging_level "${LOGLEVEL}" \
|
||||
--with-scheduler \
|
||||
"$@" &
|
||||
# Not --pid: RQ writes that file only once the worker class is imported,
|
||||
# and until then the watchdog would start a duplicate.
|
||||
echo "$!" >"/tmp/${name}.pid"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user