minor with taskManager

This commit is contained in:
lesion 2025-01-20 17:07:23 +01:00
parent 642babad94
commit e174ca02a2
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 7 additions and 3 deletions

View file

@ -14,7 +14,7 @@ module.exports = {
log.debug(`Remove ${places.length} unrelated places: %s`, places.map(p => p.name).join(', ')) log.debug(`Remove ${places.length} unrelated places: %s`, places.map(p => p.name).join(', '))
const ids = places.map(p => p.id) const ids = places.map(p => p.id)
await Place.destroy({ return Place.destroy({
where: { id: { [Sequelize.Op.in]: ids } } where: { id: { [Sequelize.Op.in]: ids } }
}) })
} }

View file

@ -2,6 +2,8 @@ const log = require('./log')
const placeHelpers = require('./helpers/place') const placeHelpers = require('./helpers/place')
const tagHelpers = require('./helpers/tag') const tagHelpers = require('./helpers/tag')
const apHelpers = require('./helpers/ap.js') const apHelpers = require('./helpers/ap.js')
const { Duration } = require('luxon')
// const notifier = require('./notifier') // const notifier = require('./notifier')
const loopInterval = 10 // process.env.NODE_ENV === 'production' ? 1 : 1 const loopInterval = 10 // process.env.NODE_ENV === 'production' ? 1 : 1
@ -24,13 +26,15 @@ class Task {
if (this.processInNTick > 0) { if (this.processInNTick > 0) {
return return
} }
log.debug(`[TASK] Process ${this.name}`)
this.processInNTick = this.repeatDelay this.processInNTick = this.repeatDelay
try { try {
const ret = this.method.apply(this, this.args) const ret = this.method.apply(this, this.args)
if (ret && typeof ret.then === 'function') { if (ret && typeof ret.catch === 'function') {
ret.catch(e => log.error(`TASK ERROR [${this.name}]: ${e} ${e.stack}`)) ret.catch(e => log.error(`TASK ERROR [${this.name}]: ${e} ${e.stack}`))
return ret return ret
} }
return ret
} catch (e) { } catch (e) {
log.error(`TASK ERROR [${this.name}]: ${e} ${e.stack}`) log.error(`TASK ERROR [${this.name}]: ${e} ${e.stack}`)
} }
@ -113,7 +117,7 @@ class TaskManager {
} }
add (task) { add (task) {
log.info(`[TASK] Add ${task.name} (${task.repeatDelay * this.interval} seconds)`) log.info(`[TASK] Add ${task.name} (${Duration.fromMillis(task.repeatDelay * this.interval * 1000).rescale().toHuman({ listStyle: "long" })})`)
this.tasks.push(task) this.tasks.push(task)
} }