-
Thanks for putting this package together. I’m thinking of using it for a particular use case and am wondering if I’m thinking about it correctly. In my app, users can create an automation that could trigger daily or monthly. They can also turn this automation off or turn it back on later. It’s mission critical that a user’s automations complete successfully and don’t interfere with other users’ automations. Here’s how I think I should set things up based on the docs: // register a function for daily and monthly orders
Jobs.register({
async createOrder(userId, data, frequency) {
// fetch some other data here to set up the next step
await externalApi.postOrder(…)
this.reschedule({in: frequency}); // {days: 1} or {months: 1}
}
})
———————————————
// user takes an action to create a new repeating automation
const repeatingOrderId = RepeatingOrders.insert({
userId,
frequency,
data,
active: true
})
// create a new job
const jobDoc = Jobs.run("createOrder", userId, data, frequency)
// update the repeating order with the jobId so we can get it later and remove
RepeatingOrders.update(repeatingOrderId,
{$set: {jobId: jobDoc._id}}
———————————————
// TIME PASSES
// user decides to stop the automation
const repeatingOrder = RepeatingOrders.findOne(id)
Jobs.remove(repeatingOrder.jobId)
RepeatingOrders.update(repeatingOrder._id,
{$set: {active: false}}
) A few questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @jamauro, thanks for considering this package. Your proposal above looks fairly solid and I think should meet your requirements. To answer your questions:
To expand on 3: there isn't a native way to prevent a job from rescheduling itself in a weekend. I guess you could do one of two things:
Also you'll need to give thought to how you define a 'weekend', particularly if you have users in different time zones, or your users are in one time zone but your server running in UTC... |
Beta Was this translation helpful? Give feedback.
Hi @jamauro, thanks for considering this package.
Your proposal above looks fairly solid and I think should meet your requirements. To answer your questions:
Jobs.Configure
, particularly themaxWait
parameter and also make suresetServerId
is not a constant string (which can be used to eliminate the wait period on single server deploy…