fix: update processEvents function to return status messages and add process_events script

This commit is contained in:
Marco Pedone 2026-02-19 12:14:34 +01:00
parent 2b87fbb161
commit 627267b86f
3 changed files with 14 additions and 3 deletions

View 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

View file

@ -1,7 +1,7 @@
import { z } from "zod/v4";
import {
apiProcedure,
createTRPCRouter,
protectedApiProcedure,
publicProcedure,
} from "~/server/api/trpc";
import {
@ -21,7 +21,7 @@ export const eventQueueRouter = createTRPCRouter({
.mutation(async ({ input }) => {
return await addEventToQueue(input);
}),
processEvents: protectedApiProcedure.query(async () => {
processEvents: apiProcedure.query(async () => {
return await processEvents();
}),
});

View file

@ -70,7 +70,7 @@ const getEventsFromQueue = async () => {
export const processEvents = async () => {
const events = await getEventsFromQueue();
if (events.length === 0) {
return;
return { message: "No events to process" };
}
for (const e of events) {
const data = e.data as EventDataTypes;
@ -93,4 +93,5 @@ export const processEvents = async () => {
.where("event_id", "=", e.event_id)
.execute();
}
return { message: `${events.length} events processed` };
};