refactor: scheduler - simple tasks handling (#5703)

pull/5733/head
Nicolas Giard 2 years ago committed by GitHub
parent f4ce5ff63e
commit 011be49ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,11 +1,14 @@
const { DynamicThreadPool } = require('poolifier')
const os = require('node:os')
const { setTimeout } = require('node:timers/promises')
const autoload = require('auto-load')
const path = require('node:path')
module.exports = {
pool: null,
maxWorkers: 1,
activeWorkers: 0,
tasks: null,
async init () {
this.maxWorkers = WIKI.config.scheduler.workers === 'auto' ? os.cpus().length : WIKI.config.scheduler.workers
WIKI.logger.info(`Initializing Worker Pool (Limit: ${this.maxWorkers})...`)
@ -14,6 +17,7 @@ module.exports = {
exitHandler: () => WIKI.logger.debug('A worker has gone offline.'),
onlineHandler: () => WIKI.logger.debug('New worker is online.')
})
this.tasks = autoload(path.join(WIKI.SERVERPATH, 'tasks/simple'))
return this
},
async start () {
@ -56,7 +60,7 @@ module.exports = {
data: job.payload
})
} else {
await this.tasks[job.task](job.payload)
}
}
})
@ -66,7 +70,7 @@ module.exports = {
},
async stop () {
WIKI.logger.info('Stopping Scheduler...')
await this.pool.stop()
await this.pool.destroy()
WIKI.logger.info('Scheduler: [ STOPPED ]')
}
}

@ -669,12 +669,12 @@ exports.up = async knex => {
await knex('jobSchedule').insert([
{
task: 'update-locales',
task: 'updateLocales',
cron: '0 0 * * *',
type: 'system'
},
{
task: 'check-version',
task: 'checkVersion',
cron: '0 0 * * *',
type: 'system'
}

@ -0,0 +1,12 @@
module.exports = async (payload) => {
WIKI.logger.info('Checking for latest version...')
try {
// TODO: Fetch latest version
WIKI.logger.info('Checked for latest version: [ COMPLETED ]')
} catch (err) {
WIKI.logger.error('Checking for latest version: [ FAILED ]')
WIKI.logger.error(err.message)
}
}

@ -0,0 +1,12 @@
module.exports = async (payload) => {
WIKI.logger.info('Fetching latest localization data...')
try {
// TODO: Fetch locale updates
WIKI.logger.info('Fetched latest localization data: [ COMPLETED ]')
} catch (err) {
WIKI.logger.error('Fetching latest localization data: [ FAILED ]')
WIKI.logger.error(err.message)
}
}
Loading…
Cancel
Save