mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +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',
|
habitrpg.controller('NotificationCtrl',
|
||||||
['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification', 'Analytics', 'Achievement', 'Social', 'Tasks',
|
['$scope', '$rootScope', 'Shared', 'Content', 'User', 'Guide', 'Notification', 'Analytics', 'Achievement', 'Social', 'Tasks',
|
||||||
function ($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) {
|
$rootScope.$watch('user', function (after, before) {
|
||||||
runYesterDailies();
|
runYesterDailies();
|
||||||
});
|
});
|
||||||
@@ -12,6 +14,8 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
});
|
});
|
||||||
|
|
||||||
function runYesterDailies() {
|
function runYesterDailies() {
|
||||||
|
if (isRunningYesterdailies) return;
|
||||||
|
|
||||||
var userLastCron = moment(User.user.lastCron).local();
|
var userLastCron = moment(User.user.lastCron).local();
|
||||||
var userDayStart = moment().startOf('day').add({ hours: User.user.preferences.dayStart });
|
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;
|
if (!Boolean(dailys) || dailys.length === 0) return;
|
||||||
|
|
||||||
|
isRunningYesterdailies = true;
|
||||||
|
|
||||||
var yesterDay = moment().subtract('1', 'day').startOf('day').add({ hours: User.user.preferences.dayStart });
|
var yesterDay = moment().subtract('1', 'day').startOf('day').add({ hours: User.user.preferences.dayStart });
|
||||||
var yesterDailies = [];
|
var yesterDailies = [];
|
||||||
dailys.forEach(function (task) {
|
dailys.forEach(function (task) {
|
||||||
@@ -31,7 +37,9 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (yesterDailies.length === 0) {
|
if (yesterDailies.length === 0) {
|
||||||
User.runCron();
|
User.runCron().then(function () {
|
||||||
|
isRunningYesterdailies = false;
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -61,7 +69,10 @@ habitrpg.controller('NotificationCtrl',
|
|||||||
});
|
});
|
||||||
|
|
||||||
$scope.ageDailies = function () {
|
$scope.ageDailies = function () {
|
||||||
User.runCron();
|
User.runCron()
|
||||||
|
.then(function () {
|
||||||
|
isRunningYesterdailies = false;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}],
|
}],
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ angular.module('habitrpg')
|
|||||||
},
|
},
|
||||||
|
|
||||||
runCron: function () {
|
runCron: function () {
|
||||||
$http({
|
return $http({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: 'api/v3/cron',
|
url: 'api/v3/cron',
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user