Skip to content

Commit

Permalink
Merge pull request #1584 from Genez-io/hotfix-sync-crons-after-fronte…
Browse files Browse the repository at this point in the history
…nd-deploy

sync cron jobs after frontend deploy
  • Loading branch information
Virgil993 authored Dec 9, 2024
2 parents edb8fd9 + e5074c0 commit 112d3bb
Showing 1 changed file with 54 additions and 53 deletions.
107 changes: 54 additions & 53 deletions src/commands/deploy/genezio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,59 +230,6 @@ export async function genezioDeploy(options: GenezioDeployOptions) {
});
}

if (configuration.services?.crons) {
printAdaptiveLog("Deploying cron jobs\n", "start");
const crons: CronDetails[] = [];
for (const cron of configuration.services.crons) {
const yamlFunctionName = await evaluateResource(
configuration,
cron.function,
options.stage || "prod",
undefined,
undefined,
);
if (!deployClassesResult) {
throw new UserError(
"Could not deploy cron jobs. Please make sure your backend is deployed before adding cron jobs.",
);
}
const functions = deployClassesResult.functions ?? [];
const cronFunction = functions.find((f) => f.name === `function-${yamlFunctionName}`);
if (!cronFunction) {
throw new UserError(
`Function ${yamlFunctionName} not found. Please make sure the function is deployed before adding cron jobs.`,
);
}
crons.push({
name: cron.name,
url: cronFunction.cloudUrl,
endpoint: cron.endpoint || "",
cronString: cron.schedule,
});
}
await syncCrons({
projectName: projectName,
stageName: options.stage || "prod",
crons: crons,
}).catch((error) => {
printAdaptiveLog("Deploying cron jobs\n", "error");
throw new UserError(
`Something went wrong while syncing the cron jobs.\n${error}\nPlease try to redeploy your project. If the problem persists, please contact support at [email protected].`,
);
});
printAdaptiveLog("Cron Jobs deployed successfully\n", "end");
} else {
await syncCrons({
projectName: projectName,
stageName: options.stage || "prod",
crons: [],
}).catch(() => {
throw new UserError(
"Something went wrong while syncing the cron jobs. Please try to redeploy your project. If the problem persists, please contact support at [email protected].",
);
});
}

const frontendUrls = [];
if (configuration.frontend && !options.backend) {
const frontends = configuration.frontend;
Expand Down Expand Up @@ -355,6 +302,60 @@ export async function genezioDeploy(options: GenezioDeployOptions) {
}
}

// Sync cron jobs after the project is created
if (configuration.services?.crons) {
printAdaptiveLog("Deploying cron jobs\n", "start");
const crons: CronDetails[] = [];
for (const cron of configuration.services.crons) {
const yamlFunctionName = await evaluateResource(
configuration,
cron.function,
options.stage || "prod",
undefined,
undefined,
);
if (!deployClassesResult) {
throw new UserError(
"Could not deploy cron jobs. Please make sure your backend is deployed before adding cron jobs.",
);
}
const functions = deployClassesResult.functions ?? [];
const cronFunction = functions.find((f) => f.name === `function-${yamlFunctionName}`);
if (!cronFunction) {
throw new UserError(
`Function ${yamlFunctionName} not found. Please make sure the function is deployed before adding cron jobs.`,
);
}
crons.push({
name: cron.name,
url: cronFunction.cloudUrl,
endpoint: cron.endpoint || "",
cronString: cron.schedule,
});
}
await syncCrons({
projectName: projectName,
stageName: options.stage || "prod",
crons: crons,
}).catch((error) => {
printAdaptiveLog("Deploying cron jobs\n", "error");
throw new UserError(
`Something went wrong while syncing the cron jobs.\n${error}\nPlease try to redeploy your project. If the problem persists, please contact support at [email protected].`,
);
});
printAdaptiveLog("Cron Jobs deployed successfully\n", "end");
} else {
await syncCrons({
projectName: projectName,
stageName: options.stage || "prod",
crons: [],
}).catch(() => {
throw new UserError(
"Something went wrong while syncing the cron jobs. Please try to redeploy your project. If the problem persists, please contact support at [email protected].",
);
});
}

// Add backend environment variables for backend deployments
// At this point the project and environment should be available in deployClassesResult
if (configuration.backend && !options.frontend && deployClassesResult) {
Expand Down

0 comments on commit 112d3bb

Please sign in to comment.