File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -76,6 +76,9 @@ const workerCatalog = {
76
76
connectionCreated : z . object ( {
77
77
id : z . string ( ) ,
78
78
} ) ,
79
+ simulate : z . object ( {
80
+ seconds : z . number ( ) ,
81
+ } ) ,
79
82
} ;
80
83
81
84
const executionWorkerCatalog = {
@@ -313,6 +316,12 @@ function getWorkerQueue() {
313
316
} ) ;
314
317
} ,
315
318
} ,
319
+ simulate : {
320
+ maxAttempts : 5 ,
321
+ handler : async ( payload , job ) => {
322
+ await new Promise ( ( resolve ) => setTimeout ( resolve , payload . seconds * 1000 ) ) ;
323
+ } ,
324
+ } ,
316
325
} ,
317
326
} ) ;
318
327
}
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ networks:
9
9
10
10
services :
11
11
db :
12
- container_name : db
12
+ container_name : devdb
13
13
image : postgres:14
14
14
restart : always
15
15
volumes :
@@ -30,6 +30,8 @@ services:
30
30
- 3030:3030
31
31
depends_on :
32
32
- db
33
+ env_file :
34
+ - ../.env
33
35
environment :
34
36
DATABASE_URL : postgres://postgres:postgres@db:5432/postgres?schema=public
35
37
DIRECT_URL : postgres://postgres:postgres@db:5432/postgres?schema=public
You can’t perform that action at this time.
0 commit comments