Search code examples
javascriptherokuparse-platformbackground-processparse-cloud-code

Can't deploy Parse background job


I am trying to get a 'hello world' background job running on heroku and then extend upon that, however whenever I try to deploy it I get the following error: TypeError: undefined is not a function

The code is as follows, and I have regular cloud functions that work just fine so I know Parse is initialized etc, what am I doing wrong here?

Broken background job

Parse.Cloud.job('myBackgroundJob', function(request, response)
{
    console.log('Running background job');
});

Working cloud code function

Parse.Cloud.define('sayHello', function(request, response)
{
    console.log('hello world');
});

Solution

  • Managed to get this working using cron, using this example as a template:

    If you do take this approach, I strongly recommend setting this up on a seperate 'worker' dyno instead of bundling with your main app, otherwise your jobs will run multiple times when adding more dynos.

    Very simply to put the index.js code in another file, and then specify that file to be used for a worker dyno in your procfile.