增加天梯排行榜
This commit is contained in:
24
jobs/jobs.js
24
jobs/jobs.js
@@ -1,21 +1,39 @@
|
||||
const schedule = require('node-schedule');
|
||||
const ladderModel = require('./ladder/ladder.model');
|
||||
|
||||
const ExecuteJobs = async() =>
|
||||
{
|
||||
//console.log('Run Hourly Jobs.....');
|
||||
|
||||
//Add custom hourly jobs here
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Execute leaderboard refresh at specified times: 00:00, 12:00, 18:00, 22:00
|
||||
const RefreshLeaderboard = async() => {
|
||||
console.log('Refreshing leaderboard...');
|
||||
try {
|
||||
await ladderModel.generateLeaderboard();
|
||||
console.log('Leaderboard refreshed successfully');
|
||||
} catch (error) {
|
||||
console.error('Error refreshing leaderboard:', error);
|
||||
}
|
||||
};
|
||||
|
||||
exports.InitJobs = function()
|
||||
{
|
||||
// Hourly jobs
|
||||
schedule.scheduleJob('* 1 * * *', function(){ // this for one hour
|
||||
ExecuteJobs();
|
||||
});
|
||||
|
||||
//Test run when starting
|
||||
// Leaderboard refresh jobs at 00:00, 12:00, 18:00, 22:00
|
||||
schedule.scheduleJob('0 0 * * *', async function() {
|
||||
const hours = new Date().getHours();
|
||||
if (hours === 0 || hours === 12 || hours === 18 || hours === 22) {
|
||||
await RefreshLeaderboard();
|
||||
}
|
||||
});
|
||||
|
||||
// Test run when starting
|
||||
ExecuteJobs();
|
||||
}
|
||||
Reference in New Issue
Block a user