clean-job-history.mjs 553 B

123456789101112131415161718
  1. import { DateTime } from 'luxon'
  2. export async function task (payload) {
  3. WIKI.logger.info('Cleaning scheduler job history...')
  4. try {
  5. await WIKI.db.knex('jobHistory')
  6. .whereNot('state', 'active')
  7. .andWhere('startedAt', '<=', DateTime.utc().minus({ seconds: WIKI.config.scheduler.historyExpiration }).toISO())
  8. .del()
  9. WIKI.logger.info('Cleaned scheduler job history: [ COMPLETED ]')
  10. } catch (err) {
  11. WIKI.logger.error('Cleaning scheduler job history: [ FAILED ]')
  12. WIKI.logger.error(err.message)
  13. throw err
  14. }
  15. }