Skip to main content

Agenda Jobs

We use agenda as our job runner instead of cron. The idea is it can execute scheduled things like calculating stats and emailing some team. It also can be used in real time to offload a side job that a web request doesn’t need to wait for. Agenda gets fired up in the app index, and starts in v2/jobs/index.js .. this file is also where we define jobs and schedule some of them. Some jobs are only defined in here, but not scheduled like preneedUserToSFandMC - a job like that we schedule or execute on the fly when a user does something. Agenda stores jobs in a mongo collection called jobCollectionName (by default). If you snoop this collection you can see each job has a name, data params, when it last ran, and when it will next run (nextRunAt). If you ever need a specific job to fire off immediately .. for testing .. or maybe its a prod thing where you want to cause preneedUserToSFandMC for a specific user to execute .. you can find this exact job instance and set the nextRunAt to a time in the past - this will cause immediate job execution.