Skip to content

Commit 0b45b79

Browse files
authored
Merge pull request #3259 from Dokploy/2680-webhook-deployments-do-not-return-a-200-ok-causing-being-repeated-over-and-over
refactor(deploy): execute deployments in background to prevent timeouts
2 parents 5f13679 + d187b52 commit 0b45b79

File tree

5 files changed

+54
-30
lines changed

5 files changed

+54
-30
lines changed

apps/dokploy/pages/api/deploy/[refreshToken].ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,19 @@ export default async function handler(
242242

243243
if (IS_CLOUD && application.serverId) {
244244
jobData.serverId = application.serverId;
245-
await deploy(jobData);
246-
return true;
245+
deploy(jobData).catch((error) => {
246+
console.error("Background deployment failed:", error);
247+
});
248+
} else {
249+
await myQueue.add(
250+
"deployments",
251+
{ ...jobData },
252+
{
253+
removeOnComplete: true,
254+
removeOnFail: true,
255+
},
256+
);
247257
}
248-
await myQueue.add(
249-
"deployments",
250-
{ ...jobData },
251-
{
252-
removeOnComplete: true,
253-
removeOnFail: true,
254-
},
255-
);
256258
} catch (error) {
257259
res.status(400).json({ message: "Error deploying Application", error });
258260
return;

apps/dokploy/pages/api/deploy/compose/[refreshToken].ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,19 @@ export default async function handler(
179179

180180
if (IS_CLOUD && composeResult.serverId) {
181181
jobData.serverId = composeResult.serverId;
182-
await deploy(jobData);
183-
return true;
182+
deploy(jobData).catch((error) => {
183+
console.error("Background deployment failed:", error);
184+
});
185+
} else {
186+
await myQueue.add(
187+
"deployments",
188+
{ ...jobData },
189+
{
190+
removeOnComplete: true,
191+
removeOnFail: true,
192+
},
193+
);
184194
}
185-
await myQueue.add(
186-
"deployments",
187-
{ ...jobData },
188-
{
189-
removeOnComplete: true,
190-
removeOnFail: true,
191-
},
192-
);
193195
} catch (error) {
194196
res.status(400).json({ message: "Error deploying Compose", error });
195197
return;

apps/dokploy/pages/api/deploy/github.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ export default async function handler(
128128

129129
if (IS_CLOUD && app.serverId) {
130130
jobData.serverId = app.serverId;
131-
await deploy(jobData);
131+
deploy(jobData).catch((error) => {
132+
console.error("Background deployment failed:", error);
133+
});
132134
continue;
133135
}
134136
await myQueue.add(
@@ -165,7 +167,9 @@ export default async function handler(
165167

166168
if (IS_CLOUD && composeApp.serverId) {
167169
jobData.serverId = composeApp.serverId;
168-
await deploy(jobData);
170+
deploy(jobData).catch((error) => {
171+
console.error("Background deployment failed:", error);
172+
});
169173
continue;
170174
}
171175

@@ -246,7 +250,9 @@ export default async function handler(
246250

247251
if (IS_CLOUD && app.serverId) {
248252
jobData.serverId = app.serverId;
249-
await deploy(jobData);
253+
deploy(jobData).catch((error) => {
254+
console.error("Background deployment failed:", error);
255+
});
250256
continue;
251257
}
252258
await myQueue.add(
@@ -291,7 +297,9 @@ export default async function handler(
291297
}
292298
if (IS_CLOUD && composeApp.serverId) {
293299
jobData.serverId = composeApp.serverId;
294-
await deploy(jobData);
300+
deploy(jobData).catch((error) => {
301+
console.error("Background deployment failed:", error);
302+
});
295303
continue;
296304
}
297305

@@ -491,7 +499,9 @@ export default async function handler(
491499

492500
if (IS_CLOUD && app.serverId) {
493501
jobData.serverId = app.serverId;
494-
await deploy(jobData);
502+
deploy(jobData).catch((error) => {
503+
console.error("Background deployment failed:", error);
504+
});
495505
continue;
496506
}
497507
await myQueue.add(

apps/dokploy/server/api/routers/application.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ export const applicationRouter = createTRPCRouter({
336336

337337
if (IS_CLOUD && application.serverId) {
338338
jobData.serverId = application.serverId;
339-
await deploy(jobData);
339+
deploy(jobData).catch((error) => {
340+
console.error("Background deployment failed:", error);
341+
});
340342
return true;
341343
}
342344
await myQueue.add(
@@ -701,7 +703,9 @@ export const applicationRouter = createTRPCRouter({
701703
};
702704
if (IS_CLOUD && application.serverId) {
703705
jobData.serverId = application.serverId;
704-
await deploy(jobData);
706+
deploy(jobData).catch((error) => {
707+
console.error("Background deployment failed:", error);
708+
});
705709

706710
return true;
707711
}
@@ -813,7 +817,9 @@ export const applicationRouter = createTRPCRouter({
813817
};
814818
if (IS_CLOUD && app.serverId) {
815819
jobData.serverId = app.serverId;
816-
await deploy(jobData);
820+
deploy(jobData).catch((error) => {
821+
console.error("Background deployment failed:", error);
822+
});
817823
return true;
818824
}
819825

apps/dokploy/server/api/routers/compose.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,9 @@ export const composeRouter = createTRPCRouter({
417417

418418
if (IS_CLOUD && compose.serverId) {
419419
jobData.serverId = compose.serverId;
420-
await deploy(jobData);
420+
deploy(jobData).catch((error) => {
421+
console.error("Background deployment failed:", error);
422+
});
421423
return true;
422424
}
423425
await myQueue.add(
@@ -453,7 +455,9 @@ export const composeRouter = createTRPCRouter({
453455
};
454456
if (IS_CLOUD && compose.serverId) {
455457
jobData.serverId = compose.serverId;
456-
await deploy(jobData);
458+
deploy(jobData).catch((error) => {
459+
console.error("Background deployment failed:", error);
460+
});
457461
return true;
458462
}
459463
await myQueue.add(

0 commit comments

Comments
 (0)