Schedule a task to happen at a specific time

I am making a very enrollment based service, where accounts are “invitation only”. Luckily, Meteor makes this very easy. The problem I am having is updating status.

I have 4 statuses:

  • User profile is created (‘new’)
  • User has been invited (‘invited’)
  • User has accepted the invitation (‘enrolled’)
  • User has declined the invitation, deactivated their account, or their email token has expired (‘unenrolled’)

The problem I am having is the unenrolled status, particularly, when their token has expired. On invitation, I do the following:

var id = Accounts.createUser({
  profile: {
    profileId: doc._id

// ... send email and whatnot

var inviteSent = Meteor.users.findOne(id).resume.loginTokens[0].when;
Students.update(doc._id, {
  $set: {
    userId: id,
    status: 'invited'
  $push: {
    invitiations: {
      sentAt: inviteSent,
      expiresAt: Accounts._tokenExpiration(inviteSent),
      accepted: false

Now the problem I am having is setting some sort of event when their token expires to set their enrollment status differently in some sort of efficient manner. I was thinking of adding some sort of pre-find hook, but it seems excessive work to do that on every find.

Ideally, I’d like to schedule an event for expiresAt to update the status to unenrolled. Is this possible?

You could set up an hourly running task that checks for expiresAt dates in the past and have not yet been processed, processes them, and ticks a mark somewhere indicating that they have. Percolate:syncedcron is very straightforward for such tasks.

1 Like

I was going to have to do scheduling for an app (never got to it though) and I book marked this for later. It looks very promising. Hope it helps!

I ask a sort-of-related question here: Scheduling Emails and came up there too. GL

Since this is the top Google result for “meteor scheduler” and SyncedCron is deprecated, I thought I’d mention that the new Steve Jobs package is designed just for Meteor and supports this kind of use case (and others too)

1 Like