mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Added check to prevent double cron (#8854)
* Added check to prevent double cron * Added then and fix style issues
This commit is contained in:
committed by
Sabe Jones
parent
ac3ac73737
commit
30437e158e
@@ -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;
|
||||
});
|
||||
};
|
||||
}],
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user