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 = {
7676 connectionCreated : z . object ( {
7777 id : z . string ( ) ,
7878 } ) ,
79+ simulate : z . object ( {
80+ seconds : z . number ( ) ,
81+ } ) ,
7982} ;
8083
8184const 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}
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ networks:
99
1010services :
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
You can’t perform that action at this time.
0 commit comments