Skip to content

Commit

Permalink
feat: add task and abort
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeauchamp committed Sep 16, 2024
1 parent 8b93a24 commit 2b708f8
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions packages/xo-server/src/api/schedule.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// FIXME so far, no acls for schedules

import { Task } from '@xen-orchestra/mixins/Tasks.mjs'

export async function getAll() {
return /* await */ this.getAllSchedules()
}
Expand Down Expand Up @@ -65,17 +67,25 @@ delete_.params = {

export { delete_ as delete }


export async function runSequence({idSchedules}){

for(const idSchedule of idSchedules){
const schedule = await this.getSchedule(idSchedule)
const job = await this.getJob(schedule.jobId)
await this.runJob(job,schedule)
}
export async function runSequence({ idSchedules }) {
const t = new Task({ properties: { type: 'xo:schedule:sequence', name: 'Schedule sequence' } })
await t.run(async () => {
const nb = idSchedules.length
const signal = Task.abortSignal
for (let i = 0; i < nb; i++) {
if (signal.aborted) {
throw new Error(signal.reason)
}
Task.set('progress', Math.round((i * 100) / nb))
const idSchedule = idSchedules[i]
const schedule = await this.getSchedule(idSchedule)
const job = await this.getJob(schedule.jobId)
await this.runJob(job, schedule)
}
})
}
runSequence.permission = 'admin'
runSequence.description = 'Run a sequence of schedule, one after the other'
runSequence.params = {
idSchedules: { type: 'array', items: { type: 'string'} },
}
idSchedules: { type: 'array', items: { type: 'string' } },
}

0 comments on commit 2b708f8

Please sign in to comment.