Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
gpt-engineer-app[bot] 2026-04-27 15:20:23 +00:00
parent 7b31f58ac9
commit fff6a3364c

View file

@ -242,12 +242,32 @@ Deno.serve(async (req) => {
let railwayServiceId: string; let railwayServiceId: string;
try { try {
railwayServiceId = await createRailwayService({ try {
token: RAILWAY_API_TOKEN, railwayServiceId = await createRailwayService({
projectId: pool.railway_project_id, token: RAILWAY_API_TOKEN,
name: serviceName, projectId: pool.railway_project_id,
}); name: serviceName,
console.log(`[provision-agent] serviço criado: ${railwayServiceId}`); });
console.log(`[provision-agent] serviço criado: ${railwayServiceId}`);
} catch (createErr) {
const msg = createErr instanceof Error ? createErr.message : String(createErr);
// Recover from "service already exists" — provavelmente sobra de attempt anterior
if (msg.includes("already exists")) {
console.warn(`[provision-agent] serviço já existe, tentando recuperar ID por nome: ${serviceName}`);
const existingId = await findRailwayServiceByName({
token: RAILWAY_API_TOKEN,
projectId: pool.railway_project_id,
name: serviceName,
});
if (!existingId) {
throw new Error(`Service "${serviceName}" exists but could not be located via API`);
}
railwayServiceId = existingId;
console.log(`[provision-agent] serviço existente recuperado: ${railwayServiceId}`);
} else {
throw createErr;
}
}
await configureRailwayService({ await configureRailwayService({
token: RAILWAY_API_TOKEN, token: RAILWAY_API_TOKEN,