You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have found that the best model to reliably process queues is to store the work in a DB and then fetch it with every run of my queue. For this I am using a supervisor (CRON) that runs once every minute to enqueue necessary syncs for resources with pending work.
To maximize the amount of work done within the 60s of the supervisor resolution I have created the following
import{differenceInSeconds}from"date-fns";import{typeQuirrelOptions,typeJobMeta}from"quirrel/dist/esm/src/client";import{Queue}from"quirrel/next-pages";import{logToSlackErrorsChannel}from"~/server/help";/** * * logging and maximum exhaustion */exportconstOngoingQueue=<T>(path: string,run: (args: T,jobMeta: JobMeta)=>Promise<boolean|void>,options?: QuirrelOptions)=>{construnBetter=async(args: T,meta: JobMeta)=>{try{conststartTime=newDate();letlastRunStart;letlastRunEnd;lettotalTime=0;letlastRunDuration=0;letruns=0;while(totalTime+lastRunDuration*2<50){console.log("run",runs);lastRunStart=newDate();constres=awaitrun(args,meta);console.log("result",res);if(typeofres=="undefined"){break;}if(res==true){// completedbreak;}lastRunEnd=newDate();lastRunDuration=differenceInSeconds(lastRunStart,lastRunEnd);totalTime=differenceInSeconds(startTime,lastRunEnd);runs++;}}catch(e){voidlogToSlackErrorsChannel((easError).stack||(easError).message);throwe;}};returnQueue(path,runBetter,options);};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have found that the best model to reliably process queues is to store the work in a DB and then fetch it with every run of my queue. For this I am using a supervisor (CRON) that runs once every minute to enqueue necessary syncs for resources with pending work.
To maximize the amount of work done within the 60s of the supervisor resolution I have created the following
Beta Was this translation helpful? Give feedback.
All reactions