Selfhosted Parse with cron jobs

Hey guys,

is there an easy approach to activate scheduled jobs in parse server?

There are some packages on npm, but none of this is working.
Thanks!

Easiest way is defining your job with Parse.Cloud.job() and schedule the jobs using your OS crontab. You can setup crontab with the periodicity you want and make it to send a request like this:

curl -X POST -H 'X-Parse-Application-Id: appId' -H 'X-Parse-Master-Key: masterKey' https://my-parse-server.com/parse/jobs/myJob
1 Like

I use this package:

https://www.npmjs.com/package/parse-server-jobs-scheduler

Install the package, add a few lines in the Parse Cloud code main file.

Configure the execution of jobs by Parse Dashboard

I used this already and somehow didn’t work. Even the npm description says it’s better to use normal crons.

I have been using it on a project for over a year.
I had no problems.
But I have a simple instance and not a cluster (which is what the documentation says, in this case cron is better.)

Hi there,

Just want to share, i also use the Parse server scheduler and so far until now i had no problems, i use it as on single instance, and it build as separate parse server from the main Parse Server, the main Parse server call the job function to the Parse server scheduler and the sceduler will run the job.

I’ve solved this problem with the following npm packages:

… and this helper function (TypeScript)

const schedule = require('node-schedule');
const axios = require('axios').default;
const logger = require('parse-server').logger;

export function scheduleCloudJob(jobname:string, cfg:string) {
    logger.info(`schedule job ${jobname} with config ${cfg}`);
    schedule.scheduleJob(cfg, function () {
        axios.create({
            baseURL: process.env.PARSE_SERVER_URL + '/jobs/' + jobname,
            timeout: 1000,
            headers: {'X-Parse-Application-Id':process.env.PARSE_SERVER_APPLICATION_ID,'X-Parse-Master-Key':process.env.PARSE_SERVER_MASTER_KEY}
        })
        .post()
        .then(function (res : any) {
            logger.info(`${jobname} triggered by scheduler`);
        })
        .catch((error : any) => {
            logger.error(`error during triggering ${jobname} by scheduler`);
            if (error.response) {
                logger.error(`${error.response.data.error};${error.response.status}`);
            } else if (error.request) {
                logger.error(error.request);
            } else { 
                logger.error(error.message);
            }
        });
    });
}

Usage:

// register cloud job myJob for running every minute
scheduleCloudJob('myJob', '0 * * * * *');

This way I don’t have to mess around with OS’s crontab which seems laborious to me to keep in sync over different Stages and operating systems.

FYI: I’ve just implemented and testet this solution. It seems to work fine but there are no long term experiences in productive environment.