chore(xo-server/utils): remove scheduleFn
This commit is contained in:
parent
31f420937e
commit
42cd5d8e58
@ -22,7 +22,6 @@ import { resolve } from 'path'
|
||||
import 'moment-timezone'
|
||||
|
||||
import through2 from 'through2'
|
||||
import { createSchedule } from '@xen-orchestra/cron'
|
||||
import { utcFormat, utcParse } from 'd3-time-format'
|
||||
import {
|
||||
all as pAll,
|
||||
@ -521,22 +520,6 @@ export const streamToArray = (stream, { filter, mapper } = {}) =>
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// Contrary to most implentations this one use the range 0-11 instead
|
||||
// of 1-12 for months.
|
||||
export const scheduleFn = (cronTime, fn, timeZone) =>
|
||||
createSchedule(cronTime, timeZone).startJob(async () => {
|
||||
try {
|
||||
await fn()
|
||||
} catch (error) {
|
||||
console.error(
|
||||
'[WARN] scheduled function:',
|
||||
(error && error.stack) || error
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// Create a serializable object from an error.
|
||||
export const serializeError = error => ({
|
||||
message: error.message,
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { BaseError } from 'make-error'
|
||||
import { createSchedule } from '@xen-orchestra/cron'
|
||||
import { noSuchObject } from 'xo-common/api-errors.js'
|
||||
|
||||
import { Schedules } from '../models/schedule'
|
||||
import { forEach, mapToArray, scheduleFn } from '../utils'
|
||||
import { forEach, mapToArray } from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@ -79,16 +80,10 @@ export default class {
|
||||
return this._scheduleTable[_resolveId(scheduleOrId)]
|
||||
}
|
||||
|
||||
_enable (schedule) {
|
||||
const { id } = schedule
|
||||
|
||||
const stopSchedule = scheduleFn(
|
||||
schedule.cron,
|
||||
() => this.xo.runJobSequence([schedule.job]),
|
||||
schedule.timezone
|
||||
_enable ({ cron, id, job, timezone }) {
|
||||
this._cronJobs[id] = createSchedule(cron, timezone).startJob(() =>
|
||||
this.xo.runJobSequence([job])
|
||||
)
|
||||
|
||||
this._cronJobs[id] = stopSchedule
|
||||
this._scheduleTable[id] = true
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user