chore(xo-server): delete unused schedules on clean
This commit is contained in:
parent
481bc9430a
commit
b7d3762c06
@ -1,7 +1,7 @@
|
||||
// FIXME so far, no acls for jobs
|
||||
|
||||
export async function getAll () {
|
||||
return /* await */ this.getAllJobs()
|
||||
return /* await */ this.getAllJobs('call')
|
||||
}
|
||||
|
||||
getAll.permission = 'admin'
|
||||
|
@ -141,13 +141,13 @@ export default class Jobs {
|
||||
})
|
||||
}
|
||||
|
||||
async getAllJobs (type: string = 'call'): Promise<Array<Job>> {
|
||||
async getAllJobs (type: ?string): Promise<Array<Job>> {
|
||||
// $FlowFixMe don't know what is the problem (JFT)
|
||||
const jobs = await this._jobs.get()
|
||||
const runningJobs = this._runningJobs
|
||||
const result = []
|
||||
jobs.forEach(job => {
|
||||
if (job.type === type) {
|
||||
if (type === undefined || job.type === type) {
|
||||
job.runId = runningJobs[job.id]
|
||||
result.push(job)
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
// @flow
|
||||
|
||||
import { createSchedule } from '@xen-orchestra/cron'
|
||||
// $FlowFixMe
|
||||
import { keyBy } from 'lodash'
|
||||
import { noSuchObject } from 'xo-common/api-errors'
|
||||
|
||||
import Collection from '../collection/redis'
|
||||
@ -58,7 +60,18 @@ export default class Scheduling {
|
||||
|
||||
this._runs = { __proto__: null }
|
||||
|
||||
app.on('clean', () => db.rebuildIndexes())
|
||||
app.on('clean', async () => {
|
||||
const [jobsById, schedules] = await Promise.all([
|
||||
app.getAllJobs().then(_ => keyBy(_, 'id')),
|
||||
app.getAllSchedules(),
|
||||
])
|
||||
|
||||
await db.remove(
|
||||
schedules.filter(_ => !(_.jobId in jobsById)).map(_ => _.id)
|
||||
)
|
||||
|
||||
return db.rebuildIndexes()
|
||||
})
|
||||
app.on('start', async () => {
|
||||
app.addConfigManager(
|
||||
'schedules',
|
||||
|
Loading…
Reference in New Issue
Block a user