Skip to content

Commit c922d24

Browse files
committed
Adding simulate graphile job to easily debug graceful shutdown retries in docker image
1 parent 70410d3 commit c922d24

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { ActionArgs, json, redirect } from "@remix-run/server-runtime";
2+
import { prisma } from "~/db.server";
3+
import { authenticateApiRequest } from "~/services/apiAuth.server";
4+
import { workerQueue } from "~/services/worker.server";
5+
6+
export async function action({ request }: ActionArgs) {
7+
// Next authenticate the request
8+
const authenticationResult = await authenticateApiRequest(request);
9+
10+
if (!authenticationResult) {
11+
return json({ error: "Invalid or Missing API key" }, { status: 401 });
12+
}
13+
14+
const adminOrgMembers = await prisma.orgMember.findMany({
15+
where: {
16+
organizationId: authenticationResult.environment.organizationId,
17+
user: {
18+
admin: true,
19+
},
20+
},
21+
});
22+
23+
if (!adminOrgMembers.length) {
24+
return json({ error: "You must be an admin to perform this action" }, { status: 403 });
25+
}
26+
27+
const body: any = await request.json();
28+
29+
await workerQueue.enqueue("simulate", {
30+
seconds: body.seconds,
31+
});
32+
33+
return json({ success: true });
34+
}

apps/webapp/app/services/worker.server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ const workerCatalog = {
7676
connectionCreated: z.object({
7777
id: z.string(),
7878
}),
79+
simulate: z.object({
80+
seconds: z.number(),
81+
}),
7982
};
8083

8184
const executionWorkerCatalog = {
@@ -313,6 +316,12 @@ function getWorkerQueue() {
313316
});
314317
},
315318
},
319+
simulate: {
320+
maxAttempts: 5,
321+
handler: async (payload, job) => {
322+
await new Promise((resolve) => setTimeout(resolve, payload.seconds * 1000));
323+
},
324+
},
316325
},
317326
});
318327
}

docker/dev-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ networks:
99

1010
services:
1111
db:
12-
container_name: db
12+
container_name: devdb
1313
image: postgres:14
1414
restart: always
1515
volumes:
@@ -30,6 +30,8 @@ services:
3030
- 3030:3030
3131
depends_on:
3232
- db
33+
env_file:
34+
- ../.env
3335
environment:
3436
DATABASE_URL: postgres://postgres:postgres@db:5432/postgres?schema=public
3537
DIRECT_URL: postgres://postgres:postgres@db:5432/postgres?schema=public

0 commit comments

Comments
 (0)