Efficient way to run scheduled function

In my app, I have a schedule option where user can select any time to send a mail to other users. We’re expecting lot of users to use this feature. So at any given minute there might be hundreds of messages we need to send out.

What is the efficient way to this?

Only idea I have in mind is creating a cron job which runs every minute and check for the messages needs to be sending out.

Anyone knows any better way ? something like queuing services where we send a call and at the scheduled time triggering webhook or something like that.

In my app users can edit the scheduled time too.

Maybe this helps (although I have recently found a bug for repeating jobs)

Did you file an issue? May I ask what kind of a bug? I use this package extensively.

Yes, I have yet to try creating a PR and some tests to fix it, but not very into coffeescript :smiley:

Interesting findings. I mostly use this package for emailing, but thanks for bringing this up.

Another option might be percolate:synced-cron. Its simpeler in my experience and have never had any issues. Just keep in mind that its not being maintained actively anymore. And although the name suggests that its just a cron script. You can actually use later.js syntax to schedule either repeating or single jobs

1 Like

I’d suggest AWS Lambda scheduled job.

See “add-scheduled-event” at https://www.claudiajs.com/documentation.html which makes using Lambda much easier.

I’ve used both synced cron and job collection, and had better luck with job collection (unfortunately I don’t remember why…). I’m going to be setting it up again in a project shortly, hopefully it’s still fun to use :slight_smile:

I’ve just made a package for this just for Meteor. It’s really efficient, and the syntax will feel familiar.

Here’s a quick example:

Jobs.register({
    sendReminder: function (to, content) {
        Email.send({
            to: to,
            from: "no-reply@jobs.com",
            subject: "Your Reminder",
            content: content,
        })
    }
});

Jobs.run("sendReminder", "jony@apple.com", "The future is here!", {
    in: {
        days: 3,
    }, 
    on: {
        hour: 9,
        minute: 42
    },
    priority: 9999999999
});