Add debug Redis configuration support, enhance Redis connection handling, and refactor worker status endpoint

This commit is contained in:
Jeppe Bundgaard
2026-03-24 10:09:37 +01:00
parent de89c4d635
commit ac164a5e81
5 changed files with 41 additions and 17 deletions
+16
View File
@@ -28,6 +28,7 @@ CONFIG_DB_HOST=
CONFIG_DB_USER=
CONFIG_DB_PASSWORD=
CONFIG_DB_DATABASE=
CONFIG_DB_PORT=3306
CONFIG_DB_SSL_MODE=DISABLED
# Debug DB credentials (used when CONFIG_DB_TARGET=debug)
@@ -36,4 +37,19 @@ CONFIG_DB_DEBUG_HOST=mysql-debug
CONFIG_DB_DEBUG_USER=root
CONFIG_DB_DEBUG_PASSWORD=debug_root_password
CONFIG_DB_DEBUG_DATABASE=nnks_db_debug
CONFIG_DB_DEBUG_PORT=3306
CONFIG_DB_DEBUG_SSL_MODE=DISABLED
# Redis credentials
REDIS_CONFIG_HOST=redis
REDIS_CONFIG_DATABASE=0
REDIS_CONFIG_PASSWORD=
REDIS_CONFIG_PORT=6379
REDIS_CONFIG_USER=default
# Redis debug credentials
REDIS_CONFIG_DEBUG_HOST=redis
REDIS_CONFIG_DEBUG_DATABASE=0
REDIS_CONFIG_DEBUG_PASSWORD=
REDIS_CONFIG_DEBUG_PORT=6379
REDIS_CONFIG_DEBUG_USER=default
+2 -1
View File
@@ -72,7 +72,8 @@ if (isset($_ENV['USE_ENV']) && $_ENV['USE_ENV'] === 'true') {
'REDIS_CONFIG_DATABASE' => 'database',
'REDIS_CONFIG_PASSWORD' => 'password',
'REDIS_CONFIG_PORT' => 'port',
'REDIS_CONFIG_USER' => 'user'
'REDIS_CONFIG_USER' => 'user',
'REDIS_CONFIG_DEBUG_PASSWORD' => 'debug_password'
];
$dbTarget = strtolower(trim((string)($_ENV['CONFIG_DB_TARGET'] ?? 'live')));
if ($dbTarget !== 'live' && $dbTarget !== 'debug') {
+2 -1
View File
@@ -28,7 +28,8 @@ if (isset($_ENV['USE_ENV']) && $_ENV['USE_ENV'] === 'true') {
'REDIS_CONFIG_DATABASE' => 'database',
'REDIS_CONFIG_PASSWORD' => 'password',
'REDIS_CONFIG_PORT' => 'port',
'REDIS_CONFIG_USER' => 'user'
'REDIS_CONFIG_USER' => 'user',
'REDIS_CONFIG_DEBUG_PASSWORD' => 'debug_password'
];
$dbTarget = strtolower(trim((string)($_ENV['CONFIG_DB_TARGET'] ?? 'live')));
if ($dbTarget !== 'live' && $dbTarget !== 'debug') {
+10 -11
View File
@@ -125,7 +125,7 @@ class workerRoute
});
$this->get('/worker/status', function () {
global /** @var router $router */
$response, $router, $db;
$response, $router, $db, $REDIS_CONFIG, $CONFIG_DB;
$response->success([
'message' => 'Worker is running',
'status' => 'OK',
@@ -135,18 +135,17 @@ class workerRoute
'version' => '1.0.1',
'routes' => $router->countRoutes(),
'redis' => [
'host' => $_ENV['REDIS_CONFIG_HOST'],
'user' => $_ENV['REDIS_CONFIG_USER'],
'database' => $_ENV['REDIS_CONFIG_DATABASE'],
//'password' => $_ENV['REDIS_CONFIG_PASSWORD'],
'port' => $_ENV['REDIS_CONFIG_PORT'],
'status' => redis->ping() ? 'OK' : 'ERROR',
'host' => $REDIS_CONFIG['host'],
'user' => $REDIS_CONFIG['user'],
'database' => $REDIS_CONFIG['database'],
'password' => $REDIS_CONFIG['password'] ? '********' : 'NOT_SET',
'port' => $REDIS_CONFIG['port'],
'status' => (new \classes\redis())->ping() ? 'OK' : 'ERROR',
],
'database' => [
'host' => $_ENV['CONFIG_DB_HOST'],
'database' => $_ENV['CONFIG_DB_DATABASE'],
'user' => $_ENV['CONFIG_DB_USER'],
'host' => $CONFIG_DB['host'],
'database' => $CONFIG_DB['database'],
'user' => $CONFIG_DB['user'],
'status' => $db->testConnection() ? 'OK' : 'ERROR',
],
]);
+11 -4
View File
@@ -12,13 +12,20 @@ AUTO_COMPOSER_INSTALL="${AUTO_COMPOSER_INSTALL:-true}"
log() { printf "[entrypoint] %s\n" "$*"; }
wait_for_redis() {
host="${REDIS_CONFIG_HOST:-redis}"
port="${REDIS_CONFIG_PORT:-6379}"
pass="${REDIS_CONFIG_PASSWORD:-}"
db_target="${CONFIG_DB_TARGET:-live}"
if [ "$db_target" = "debug" ]; then
host="${REDIS_CONFIG_DEBUG_HOST:-${REDIS_CONFIG_HOST:-redis}}"
port="${REDIS_CONFIG_DEBUG_PORT:-${REDIS_CONFIG_PORT:-6379}}"
pass="${REDIS_CONFIG_DEBUG_PASSWORD:-${REDIS_CONFIG_PASSWORD:-}}"
else
host="${REDIS_CONFIG_HOST:-redis}"
port="${REDIS_CONFIG_PORT:-6379}"
pass="${REDIS_CONFIG_PASSWORD:-}"
fi
timeout="${REDIS_WAIT_TIMEOUT:-60}"
i=0
log "Waiting for Redis at ${host}:${port} (timeout: ${timeout}s) ..."
log "Waiting for Redis at ${host}:${port} (target: ${db_target}, timeout: ${timeout}s) ..."
while [ "$i" -lt "$timeout" ]; do
if [ -n "$pass" ]; then
if redis-cli -h "$host" -p "$port" -a "$pass" PING >/dev/null 2>&1; then