mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
cron: set lastCron at the beginning and misc fixes
This commit is contained in:
committed by
Blade Barringer
parent
c0d9c54c44
commit
e07ade5a4a
@@ -12,6 +12,29 @@ const shouldDo = common.shouldDo;
|
||||
const scoreTask = common.ops.scoreTask;
|
||||
// const maxPMs = 200;
|
||||
|
||||
export async function recoverCron (status, locals) {
|
||||
let {user} = locals;
|
||||
|
||||
await Bluebird.delay(300);
|
||||
|
||||
let reloadedUser = await User.findOne({_id: user._id}).exec();
|
||||
|
||||
if (!reloadedUser) {
|
||||
throw new Error(`User ${user._id} not found while recovering.`);
|
||||
} else if (reloadedUser._cronSignature !== 'NOT_RUNNING') {
|
||||
status.times++;
|
||||
|
||||
if (status.times < 5) {
|
||||
await recoverCron(status, locals);
|
||||
} else {
|
||||
throw new Error(`Impossible to recover from cron for user ${user._id}.`);
|
||||
}
|
||||
} else {
|
||||
locals.user = reloadedUser;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
let CLEAR_BUFFS = {
|
||||
str: 0,
|
||||
int: 0,
|
||||
@@ -83,29 +106,6 @@ function performSleepTasks (user, tasksByType, now) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function recoverCron (status, locals) {
|
||||
let {user} = locals;
|
||||
|
||||
await Bluebird.delay(300);
|
||||
|
||||
let reloadedUser = await User.findOne({_id: user._id}).exec();
|
||||
|
||||
if (!reloadedUser) {
|
||||
throw new Error(`User ${user._id} not found while recovering.`);
|
||||
} else if (reloadedUser._cronSignature !== 'NOT_RUNNING') {
|
||||
status.times++;
|
||||
|
||||
if (status.times < 4) {
|
||||
await recoverCron(status, locals);
|
||||
} else {
|
||||
throw new Error(`Impossible to recover from cron for user ${user._id}.`);
|
||||
}
|
||||
} else {
|
||||
locals.user = reloadedUser;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Perform various beginning-of-day reset actions.
|
||||
export function cron (options = {}) {
|
||||
let {user, tasksByType, analytics, now = new Date(), daysMissed, timezoneOffsetFromUserPrefs} = options;
|
||||
|
||||
Reference in New Issue
Block a user