Introducing Background Jobs

Blog-Post-Jobs

Today we’re excited to introduce Background Jobs. We’ve listened to your feedback and this was one of the most requested features. Background Jobs allow you to set up long running tasks by writing code similar to Cloud Functions:

Parse.Cloud.job("userMigration", function(request, status) {
  // Set up to modify user data
  Parse.Cloud.useMasterKey();
  // Query for all users
  var query = new Parse.Query(Parse.User);
  query.each(function(user) {
      // Set and save the change
      user.set("plan", request.params.plan);
      return user.save();
  }).then(function() {
    // Set the job's success status
    status.success("Migration completed successfully.");
  }, function(error) {
    // Set the job's error status
    status.error("Uh oh, something went wrong.");
  });
});

In the above code example, a user migration Background Job has been defined to update a plan field in the Parse.User object. This is a good candidate for a Background Job as it could be a long running process that could timeout if set up as a Cloud Function.

Once you’ve deployed your code, you can add it as a new entry to the jobs schedule in the Web Console. There are many options available to customize the frequency of your jobs, including the start time. You can also view the status of any currently running jobs or previous jobs that have been completed.

screenshot of UI for managing your background jobs

For more information about Background Jobs, check out the Cloud Code Guide.

Brad Kittenbrink
September 4, 2013
blog comments powered by Disqus

Comments are closed.

Archives

Categories

RSS Feed Follow us Like us