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

@ -241,6 +241,7 @@ Deno.serve(async (req) => {
console.log(`[provision-agent] criando serviço Railway: ${serviceName}`);
let railwayServiceId: string;
try {
try {
railwayServiceId = await createRailwayService({
token: RAILWAY_API_TOKEN,
@ -248,6 +249,25 @@ Deno.serve(async (req) => {
name: serviceName,
});
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({
token: RAILWAY_API_TOKEN,