Recommendations for Cron Job Packages?

My app is running on Galaxy, and I need to install a cron job package with the following features:

  • If my app scales to multiple servers, it will make sure only one is running the cron job
  • Does not require Mongo (my app uses Postgres)

It looks like the most recent cron job thread here is from a few years ago, so this may be a good time for a quick thread about this. :slightly_smiling_face:

We modified the code in percolate:synced-cron to use MySQL instead of MongoDB. It could easily be made to work with PostgreSQL.

1 Like

That is great news! Does the code need any changes to work with PostgreSQL?

We are using bullmq which uses redis.

@vikr00001,

I have extracted my MySQL-enabled SyncedCron code from one of our projects into a standalone example. I have made it available as a GitHub gist containing 3 files - db.js (database initialization), cron.js (the MySQL-enabled SyncedCron code) and main.js (upon Meteor startup, it creates an example SyncedCron job that prints β€œTime to wake up!” every day at 7am.

Instructions:

  1. Create a new meteor app with the default settings and replace the files in the server folder with these

    meteor create mysqlsyncedcrontest

  2. Put the above 3 files from the gist into the server folder

  3. Install the required Atmosphere and NPM dependencies

    meteor add check
    meteor npm install lodash, mysql2, later

  4. Remove the meteor.mainModule lines from package.json in the root folder.

  5. You should now be able to run the example.

Modifying it to work with PostgreSQL

I presume your Meteor app would be using the node-postgres package.

It is not difficult to modify this code to work with PostgreSQL. These are the primary changes needed:

  1. You will have to manually create the cron_history table in your PostgreSQL database. There is a MySQL table schema definition in the comments at the top of cron.js. You would have to create this table using PostgreSQL syntax and data types.

  2. You will have to modify the code in db.js to work with the node-postgres package instead of mysql2. I had a quick peek. I see that the semantics are very similar.

  3. You may have to tweak the 5 lines of code in cron.js that call qLiveDb() to ensure the SQL is valid for PostgreSQL.

1 Like

Fantastic. Thanks very much, @vlasky! I look forward to checking it out.

I have a few questions as I work through this. May I ping on on DM so as not to clutter up the thread?

@vlasky, the SyncedCron code is running great and is just what my app needed. Thanks very much for your help!

1 Like

Excellent work! I am delighted to have been of assistance.