In my webapp, users can create recurring invoices that need to be generated and sent out at certain dates each month. For example, an invoice might need to be sent out on the 5th of every month.
I am using Kue to process all my background jobs so I want to do it in this case as well.
My current solution is to use setInterval()
to create a processRecurringInvoices
job every hour. This job will then find all recurring invoices from database and create a separate generateInvoice
job for each recurring invoice.
The generateInvoice
job will then actually generate the invoice, and if needed, will also in turn create a sendInvoiceToEmail
job that will email the invoice.
At the moment this solution looks good to me, because it has a nice separation of concerns, however, I have the following questions:
processRecurringInvoices
job?processRecurringInvoices
job or should I handle them separately for each job?processRecurringInvoices
or any of the child jobs are still runnning, the processRecurringInvoices
job is not created again? Kind of like a unique job, or mutual exclusion?kue.Job.rangeByType()
to search for currently active jobs. If a job is active, you can skip kicking it off again.