错误消息 - 失败:未调用成功/错误

时间:2015-04-21 07:42:26

标签: parse-platform cloud-code

Parse.Cloud.job("JobSchedule", function(request, response) {

    var Group = Parse.Object.extend("Group");
    var query = new Parse.Query(Group);
    query.equalTo("JobScheduled", true);
    query.find({
        success: function(results) {
            for (var i = 0; i < results.length; ++i) {
                var created = new Date(results[i].createdAt);
                var current = new Date();
                var timeDiff = Math.abs(current.getTime() - created.getTime());
                var horsDiff = timeDiff / (60 * 60 * 1000);
                if (horsDiff >= parseInt(results[i].get("JobHours"))) {
                    results[i].set("JobScheduled", false);
                    results[i].set("GroupType", "Private");
                    results[i].set("JobHours", 0);
                    results[i].save();

                    var GroupMembers = Parse.Object.extend("GroupMembers");
                    var query1 = new Parse.Query(GroupMembers);
                    query1.equalTo("GroupId", results[i].id);
                    query1.find({
                        success: function(grpresults) {
                            for (var j = 0; j < grpresults.length; ++j) {
                                grpresults[j].set("GroupType", "Private");
                                grpresults[j].save();
                            }
                        },
                        error: function(error) {
                            response.error(error);
                        }
                    })
                }
            }
        },
        error: function(error) {
            response.error(error);
        }
    });
});

脚本正常运行(它按定义更新值)。但是在解析日志中它显示为失败:未调用成功/错误。请在这个问题上建议我

1 个答案:

答案 0 :(得分:2)

您根本不会致电response.success()response.error(),而且您应该至少拨打其中一个。

你应该真正存储从查询中返回的所有承诺,并保存并等待所有承诺完成,然后根据这些承诺的结果调用成功或错误。