fix: update processEvents function to return status messages and add process_events script
This commit is contained in:
parent
2b87fbb161
commit
627267b86f
3 changed files with 14 additions and 3 deletions
10
apps/backend/scripts/process_events.sh
Normal file
10
apps/backend/scripts/process_events.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e # Exit on any error
|
||||||
|
|
||||||
|
echo "Starting Process Events job..."
|
||||||
|
if curl -sS -f --connect-timeout 30 --max-time 300 "http://web:3000/api/trpc/eventQueue.processEvents"; then
|
||||||
|
echo "Process Events job completed successfully"
|
||||||
|
else
|
||||||
|
echo "Process Events job failed" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
import {
|
import {
|
||||||
|
apiProcedure,
|
||||||
createTRPCRouter,
|
createTRPCRouter,
|
||||||
protectedApiProcedure,
|
|
||||||
publicProcedure,
|
publicProcedure,
|
||||||
} from "~/server/api/trpc";
|
} from "~/server/api/trpc";
|
||||||
import {
|
import {
|
||||||
|
|
@ -21,7 +21,7 @@ export const eventQueueRouter = createTRPCRouter({
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
return await addEventToQueue(input);
|
return await addEventToQueue(input);
|
||||||
}),
|
}),
|
||||||
processEvents: protectedApiProcedure.query(async () => {
|
processEvents: apiProcedure.query(async () => {
|
||||||
return await processEvents();
|
return await processEvents();
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ const getEventsFromQueue = async () => {
|
||||||
export const processEvents = async () => {
|
export const processEvents = async () => {
|
||||||
const events = await getEventsFromQueue();
|
const events = await getEventsFromQueue();
|
||||||
if (events.length === 0) {
|
if (events.length === 0) {
|
||||||
return;
|
return { message: "No events to process" };
|
||||||
}
|
}
|
||||||
for (const e of events) {
|
for (const e of events) {
|
||||||
const data = e.data as EventDataTypes;
|
const data = e.data as EventDataTypes;
|
||||||
|
|
@ -93,4 +93,5 @@ export const processEvents = async () => {
|
||||||
.where("event_id", "=", e.event_id)
|
.where("event_id", "=", e.event_id)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
return { message: `${events.length} events processed` };
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue