mirror of
https://github.com/domfelipe/mika-agent-assist.git
synced 2026-08-07 07:56:42 +00:00
Changes
Co-authored-by: domfelipe <53182096+domfelipe@users.noreply.github.com>
This commit is contained in:
parent
9f5b698d3a
commit
3b5137decd
1 changed files with 58 additions and 9 deletions
|
|
@ -148,18 +148,67 @@ export async function setRailwayReplicas(opts: {
|
||||||
serviceInstanceUpdate(serviceId: $serviceId, environmentId: $environmentId, input: $input)
|
serviceInstanceUpdate(serviceId: $serviceId, environmentId: $environmentId, input: $input)
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
const res = await railwayQuery(
|
// Tenta numReplicas primeiro (formato atual da Railway API v2)
|
||||||
|
const tryWithKey = async (key: "numReplicas" | "replicas") => {
|
||||||
|
return await railwayQuery(
|
||||||
mutation,
|
mutation,
|
||||||
{
|
{
|
||||||
serviceId: opts.serviceId,
|
serviceId: opts.serviceId,
|
||||||
environmentId: opts.environmentId,
|
environmentId: opts.environmentId,
|
||||||
input: { numReplicas: opts.replicas },
|
input: { [key]: opts.replicas },
|
||||||
},
|
},
|
||||||
opts.token,
|
opts.token,
|
||||||
);
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
let res = await tryWithKey("numReplicas");
|
||||||
|
if (res.errors?.length) {
|
||||||
|
const msg = JSON.stringify(res.errors);
|
||||||
|
// Fallback para `replicas` se o schema reclamar do campo
|
||||||
|
if (/numReplicas/i.test(msg) && /(unknown|not.*found|invalid)/i.test(msg)) {
|
||||||
|
console.warn("setRailwayReplicas: numReplicas rejected, retrying with `replicas`");
|
||||||
|
res = await tryWithKey("replicas");
|
||||||
|
}
|
||||||
|
}
|
||||||
if (res.errors?.length) {
|
if (res.errors?.length) {
|
||||||
throw new Error(`setRailwayReplicas failed: ${JSON.stringify(res.errors)}`);
|
throw new Error(`setRailwayReplicas failed: ${JSON.stringify(res.errors)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Após escalar, força redeploy para aplicar a mudança imediatamente
|
||||||
|
try {
|
||||||
|
await deployRailwayService({
|
||||||
|
token: opts.token,
|
||||||
|
serviceId: opts.serviceId,
|
||||||
|
environmentId: opts.environmentId,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("setRailwayReplicas: redeploy after scale failed (non-fatal):", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Busca o environmentId do primeiro deployment de um serviço. Útil quando vps_pool_id está null. */
|
||||||
|
export async function getServiceEnvironmentId(opts: {
|
||||||
|
token: string;
|
||||||
|
serviceId: string;
|
||||||
|
}): Promise<string | null> {
|
||||||
|
const query = `
|
||||||
|
query Service($id: String!) {
|
||||||
|
service(id: $id) {
|
||||||
|
projectId
|
||||||
|
deployments(first: 1) {
|
||||||
|
edges { node { environmentId } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
const res = await railwayQuery<{
|
||||||
|
service: { projectId: string; deployments: { edges: { node: { environmentId: string } }[] } };
|
||||||
|
}>(query, { id: opts.serviceId }, opts.token);
|
||||||
|
if (res.errors?.length) {
|
||||||
|
console.error("getServiceEnvironmentId errors:", JSON.stringify(res.errors));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return res.data?.service?.deployments?.edges?.[0]?.node?.environmentId ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Apaga o webhook do Telegram para que o Hermes assuma via polling. */
|
/** Apaga o webhook do Telegram para que o Hermes assuma via polling. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue