解析后台作业在计划时失败,但在手动启动时成功

时间:2015-09-07 08:00:15

标签: javascript parse-platform

我的后台工作有问题,应该每晚安排0:00。过去两天,这项工作在安排时失败了:

  

E2015-09-03T00:00:11.525Z] v24 Ran job deleteAndSaveScores with:输入:{}结果:未调用成功/错误

但是,当我通过仪表板手动启动它时,它不会失败并且完美运行:

  

I2015-09-04T07:15:25.942Z] v24:Ran job deleteAndSaveScores with:输入:{}结果:迁移成功完成。

这是我的工作:

Parse.Cloud.job("deleteAndSaveScores", function(request, status) {
 // Query for all scores
 var ScoresCalc = Parse.Object.extend("ScoresCalc");
 var query = new Parse.Query(ScoresCalc);
 var currentTime = new Date();
 currentTime.setHours(0,0,0,0);

 var ScoresYesterday = Parse.Object.extend("ScoresYesterday");
 var queryScoresYesterday = new Parse.Query(ScoresYesterday);

 queryScoresYesterday.each(function(scoreYest){
 scoreYest.destroy();
 }).then(function(){
 query.each(function(scoreCalc) {

 var GameScore = Parse.Object.extend("ScoresYesterday");
 var scoreyes = new GameScore();
 var PeopleCalc = scoreCalc.get("People");
 var QuestionCalc = scoreCalc.get("Question");
 var nbNotesCalc = scoreCalc.get("nbNotes");
 var totalNotesCalc = scoreCalc.get("totalNotes");


 scoreyes.set("People",PeopleCalc);
 scoreyes.set("Question",QuestionCalc);
 scoreyes.set("nbNotes",nbNotesCalc);
 scoreyes.set("totalNotes",totalNotesCalc);
 scoreyes.set("date", currentTime);

 return scoreyes.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.");
 });
});
});

我想知道它有什么问题。

编辑:我用""

时所做的更改
Parse.Cloud.job("deleteAndSaveScores2", function(request, status) {
  // Query for all scores
  var ScoresCalc = Parse.Object.extend("ScoresCalc");
  var query = new Parse.Query(ScoresCalc);
  var currentTime = new Date();
  currentTime.setHours(0,0,0,0);
  var listOfPromises = [];

  var ScoresYesterday = Parse.Object.extend("ScoresYesterday");
  var queryScoresYesterday = new Parse.Query(ScoresYesterday);

  queryScoresYesterday.each(function(scoreYest){
    scoreYest.destroy();
  }).then(function(){
    query.each(function(scoreCalc) {

    var GameScore = Parse.Object.extend("ScoresYesterday");
    var scoreyes = new GameScore();
    var PeopleCalc = scoreCalc.get("People");
    var QuestionCalc = scoreCalc.get("Question");
    var nbNotesCalc = scoreCalc.get("nbNotes");
    var totalNotesCalc = scoreCalc.get("totalNotes");


    scoreyes.set("People",PeopleCalc);
    scoreyes.set("Question",QuestionCalc);
    scoreyes.set("nbNotes",nbNotesCalc);
    scoreyes.set("totalNotes",totalNotesCalc);
    scoreyes.set("date", currentTime);

    listOfPromises.push(scoreyes.save());
  })
}).then(function() {
  Parse.Promise.when(listOfPromises).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.");
   });
});
});

0 个答案:

没有答案