feat: extend main-server artifact consumers
This commit is contained in:
@@ -2681,6 +2681,9 @@ fn main() {
|
||||
if env::args().any(|arg| arg == "--healthcheck") {
|
||||
std::process::exit(if run_healthcheck(config.port) { 0 } else { 1 });
|
||||
}
|
||||
if env::args().any(|arg| arg == "--print-health") {
|
||||
std::process::exit(if print_health(config.port) { 0 } else { 1 });
|
||||
}
|
||||
let state = AppState {
|
||||
config,
|
||||
started_at: now_iso(),
|
||||
@@ -2726,6 +2729,30 @@ fn run_healthcheck(port: u16) -> bool {
|
||||
stream.read_to_string(&mut body).is_ok() && body.contains("\"ok\": true")
|
||||
}
|
||||
|
||||
fn print_health(port: u16) -> bool {
|
||||
let Ok(mut stream) = TcpStream::connect(("127.0.0.1", port)) else {
|
||||
return false;
|
||||
};
|
||||
let _ = stream.set_read_timeout(Some(std::time::Duration::from_secs(3)));
|
||||
let _ = stream.set_write_timeout(Some(std::time::Duration::from_secs(3)));
|
||||
if stream
|
||||
.write_all(b"GET /health HTTP/1.1\r\nHost: 127.0.0.1\r\nConnection: close\r\n\r\n")
|
||||
.is_err()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
let mut response = String::new();
|
||||
if stream.read_to_string(&mut response).is_err() {
|
||||
return false;
|
||||
}
|
||||
if let Some((_, body)) = response.split_once("\r\n\r\n") {
|
||||
println!("{}", body.trim());
|
||||
} else {
|
||||
println!("{}", response.trim());
|
||||
}
|
||||
response.contains("\"ok\": true")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -16,6 +16,11 @@ interface RuntimeConfig {
|
||||
pipelineBridgeBaseUrl: string;
|
||||
pipelineBridgeIntervalMs: number;
|
||||
pipelineBridgeRunLimit: number;
|
||||
deployServiceId: string;
|
||||
deployRef: string;
|
||||
deployRepo: string;
|
||||
deployCommit: string;
|
||||
deployRequestedCommit: string;
|
||||
}
|
||||
|
||||
interface OaEventInput {
|
||||
@@ -184,6 +189,11 @@ function configFromEnv(): RuntimeConfig {
|
||||
pipelineBridgeBaseUrl: envString("PIPELINE_OA_BRIDGE_BASE_URL", "").replace(/\/+$/u, ""),
|
||||
pipelineBridgeIntervalMs: envNumber("PIPELINE_OA_BRIDGE_INTERVAL_MS", 15_000),
|
||||
pipelineBridgeRunLimit: envNumber("PIPELINE_OA_BRIDGE_RUN_LIMIT", 50),
|
||||
deployServiceId: envString("UNIDESK_DEPLOY_SERVICE_ID", "oa-event-flow"),
|
||||
deployRef: envString("UNIDESK_DEPLOY_REF", ""),
|
||||
deployRepo: envString("UNIDESK_DEPLOY_REPO", ""),
|
||||
deployCommit: envString("UNIDESK_DEPLOY_COMMIT", ""),
|
||||
deployRequestedCommit: envString("UNIDESK_DEPLOY_REQUESTED_COMMIT", ""),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1328,6 +1338,13 @@ async function healthRoute(): Promise<Response> {
|
||||
insertedCount: pipelineBridgeState.insertedCount,
|
||||
duplicateCount: pipelineBridgeState.duplicateCount,
|
||||
},
|
||||
deploy: {
|
||||
serviceId: config.deployServiceId,
|
||||
ref: config.deployRef,
|
||||
repo: config.deployRepo,
|
||||
commit: config.deployCommit,
|
||||
requestedCommit: config.deployRequestedCommit,
|
||||
},
|
||||
}, databaseReady ? 200 : 503);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,11 @@ interface RuntimeConfig {
|
||||
databaseUrl: string;
|
||||
logFile: string;
|
||||
databasePoolMax: number;
|
||||
deployServiceId: string;
|
||||
deployRef: string;
|
||||
deployRepo: string;
|
||||
deployCommit: string;
|
||||
deployRequestedCommit: string;
|
||||
}
|
||||
|
||||
interface ProjectRow {
|
||||
@@ -92,6 +97,11 @@ function configFromEnv(): RuntimeConfig {
|
||||
databaseUrl,
|
||||
logFile: process.env.LOG_FILE || "",
|
||||
databasePoolMax: Math.max(1, Math.min(8, Number(process.env.DATABASE_POOL_MAX || 1) || 1)),
|
||||
deployServiceId: process.env.UNIDESK_DEPLOY_SERVICE_ID || "project-manager",
|
||||
deployRef: process.env.UNIDESK_DEPLOY_REF || "",
|
||||
deployRepo: process.env.UNIDESK_DEPLOY_REPO || "",
|
||||
deployCommit: process.env.UNIDESK_DEPLOY_COMMIT || "",
|
||||
deployRequestedCommit: process.env.UNIDESK_DEPLOY_REQUESTED_COMMIT || "",
|
||||
};
|
||||
}
|
||||
|
||||
@@ -569,6 +579,13 @@ async function health(): Promise<Response> {
|
||||
service: "project-manager",
|
||||
storage: { primary: "postgres", table: "project_manager_projects", projects: Number(rows[0]?.count ?? 0) },
|
||||
capabilities: ["crud", "excel-import", "excel-export"],
|
||||
deploy: {
|
||||
serviceId: config.deployServiceId,
|
||||
ref: config.deployRef,
|
||||
repo: config.deployRepo,
|
||||
commit: config.deployCommit,
|
||||
requestedCommit: config.deployRequestedCommit,
|
||||
},
|
||||
startedAt: serviceStartedAt,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user