Added check to prevent double cron (#8854)

* Added check to prevent double cron

* Added then and fix style issues
This commit is contained in:
Keith Holliday
2017-07-07 12:14:36 -06:00
committed by Sabe Jones
parent ac3ac73737
commit 30437e158e
2 changed files with 14 additions and 3 deletions

View File

@@ -3,6 +3,8 @@
habitrpg.controller('NotificationCtrl',
['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification', 'Analytics', 'Achievement', 'Social', 'Tasks',
function ($scope, $rootScope, Shared, Content, User, Guide, Notification, Analytics, Achievement, Social, Tasks) {
var isRunningYesterdailies = false;
$rootScope.$watch('user', function (after, before) {
runYesterDailies();
});
@@ -12,6 +14,8 @@ habitrpg.controller('NotificationCtrl',
});
function runYesterDailies() {
if (isRunningYesterdailies) return;
var userLastCron = moment(User.user.lastCron).local();
var userDayStart = moment().startOf('day').add({ hours: User.user.preferences.dayStart });
@@ -20,6 +24,8 @@ habitrpg.controller('NotificationCtrl',
if (!Boolean(dailys) || dailys.length === 0) return;
isRunningYesterdailies = true;
var yesterDay = moment().subtract('1', 'day').startOf('day').add({ hours: User.user.preferences.dayStart });
var yesterDailies = [];
dailys.forEach(function (task) {
@@ -31,7 +37,9 @@ habitrpg.controller('NotificationCtrl',
});
if (yesterDailies.length === 0) {
User.runCron();
User.runCron().then(function () {
isRunningYesterdailies = false;
});
return;
};
@@ -61,7 +69,10 @@ habitrpg.controller('NotificationCtrl',
});
$scope.ageDailies = function () {
User.runCron();
User.runCron()
.then(function () {
isRunningYesterdailies = false;
});
};
}],
});

View File

@@ -418,7 +418,7 @@ angular.module('habitrpg')
},
runCron: function () {
$http({
return $http({
method: "POST",
url: 'api/v3/cron',
})