-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1584 from Genez-io/hotfix-sync-crons-after-fronte…
…nd-deploy sync cron jobs after frontend deploy
- Loading branch information
Showing
1 changed file
with
54 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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) { | ||
|