mise en place des tâches terra et guac en parallèle
This commit is contained in:
parent
74b0639ac6
commit
be23cf5891
@ -68,8 +68,36 @@ export const handleApplyJob = async (formationId: string, req: ApplyRequest) =>
|
||||
// Terraform init
|
||||
await runTerraformCommand(remoteDir, 'init -input=false -upgrade');
|
||||
|
||||
// Terraform apply
|
||||
await runTerraformCommand(remoteDir, 'apply -auto-approve -input=false');
|
||||
// Prepare Terraform Apply Promise
|
||||
const terraformApplyPromise = runTerraformCommand(remoteDir, 'apply -auto-approve -input=false');
|
||||
|
||||
// Prepare Guacamole Provisioning Promise
|
||||
let guacamolePromise: Promise<void> = Promise.resolve();
|
||||
if (req.guacamole) {
|
||||
logger.info(`Starting Guacamole provisioning for formation ${formationId}`);
|
||||
guacamolePromise = guacamoleService.provision(
|
||||
formationId,
|
||||
req.guacamole.groupName,
|
||||
req.guacamole.users,
|
||||
req.vms.map(vm => ({
|
||||
name: vm.name,
|
||||
ip: vm.ip,
|
||||
rdpDomain: vm.rdpDomain,
|
||||
rdpPort: vm.rdpPort,
|
||||
}))
|
||||
).then(() => {
|
||||
logger.info(`Guacamole provisioning succeeded for formation ${formationId}`);
|
||||
}).catch((error: any) => {
|
||||
logger.error(`Guacamole provisioning failed for formation ${formationId}: ${error.message}`);
|
||||
if (error.config) logger.error(`Failed request: ${error.config.method?.toUpperCase()} ${error.config.url}`);
|
||||
if (error.response) logger.error(`Response status: ${error.response.status}`);
|
||||
// We might want to re-throw or handle this differently depending on if we want the whole job to fail
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
// Run both in parallel
|
||||
await Promise.all([terraformApplyPromise, guacamolePromise]);
|
||||
|
||||
// Save to DB
|
||||
await prisma.terraform_formations.create({
|
||||
@ -80,30 +108,6 @@ export const handleApplyJob = async (formationId: string, req: ApplyRequest) =>
|
||||
guacamole_group_name: req.guacamole?.groupName,
|
||||
}
|
||||
});
|
||||
|
||||
// Provision Guacamole
|
||||
if (req.guacamole) {
|
||||
try {
|
||||
logger.info(`Starting Guacamole provisioning for formation ${formationId}`);
|
||||
await guacamoleService.provision(
|
||||
formationId,
|
||||
req.guacamole.groupName,
|
||||
req.guacamole.users,
|
||||
req.vms.map(vm => ({
|
||||
name: vm.name,
|
||||
ip: vm.ip,
|
||||
rdpDomain: vm.rdpDomain,
|
||||
rdpPort: vm.rdpPort,
|
||||
}))
|
||||
);
|
||||
logger.info(`Guacamole provisioning succeeded for formation ${formationId}`);
|
||||
} catch (error: any) {
|
||||
logger.error(`Guacamole provisioning failed for formation ${formationId}: ${error.message}`);
|
||||
// Log details if available
|
||||
if (error.config) logger.error(`Failed request: ${error.config.method?.toUpperCase()} ${error.config.url}`);
|
||||
if (error.response) logger.error(`Response status: ${error.response.status}`);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Cleanup on failure if it was created during this job
|
||||
await cleanupRemote(remoteDir);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user