Invalid job

95 views
Skip to first unread message

Christian Høfler

unread,
Jul 12, 2017, 11:40:11 AM7/12/17
to Back4App
I have a background job, which is running fine when I run it manually, but when it runs automatically as a scheduled job, it doesn't work and writes:

Wed Jul 12 2017 15:31:05 GMT+0000 (UTC)
 [31merror [39m: Invalid job. code=141, message=Invalid job.

Wed Jul 12 2017 15:31:05 GMT+0000 (UTC) 
 [31merror [39m: Error generating response. ParseError { code: 141, message: 'Invalid job.' } code=141, message=Invalid job.

 in the server log. It should delete all images that are older than 24 hours.

This is my job:

Parse.Cloud.job("deleteAfter24", function(request, status) {

    Parse.Cloud.useMasterKey();

    var ts = Math.round(new Date().getTime() / 1000);
    var tsYesterday = ts - (24 * 3600);
    var dateYesterday = new Date(tsYesterday*1000);

    var imageQuery = new Parse.Query("Image");

    imageQuery.lessThan("createdAt", dateYesterday);

    imageQuery.find({
        success: function(result) {
            for (var i=0; i<result.length; i++) {
                result[i].destroy({
                    success: function(object) {
                        status.success("Delete job completed");
                        alert('Delete Successful');
                    },
                    error: function(object, error) {
                        status.error("Delete error :" + error);
                        //response.error('Delete failed');
                        console.log(error);
                    }
                });
            }
            status.success("Delete job completed");
        },
        error: function(error) {
            status.error("Error in snap delete query error: " + error);
            //response.error('Error in delete query');
        },
        useMasterKey: true
    });
});

casag...@back4app.com

unread,
Jul 12, 2017, 2:53:37 PM7/12/17
to Back4App
Hello!

In which Parse Server version are you right now? This method Parse.Cloud.useMasterKey(); is deprecated in the latest version, so I'd suggest not using it as well. 
Finally, the Job works completely and properly when running it manually? How do you run it manually and how do you schedule it? 

If you prefer, you can send your appId to us at comm...@back4app.com or at the Online Chat so we can assist you specially with this app.

Best!
Reply all
Reply to author
Forward
0 new messages