wait for pending to be available to claim task
Signed-off-by: Hao Luo <howlowck@gmail.com>
This commit is contained in:
@@ -110,13 +110,26 @@ export class TaskWorker {
|
||||
start() {
|
||||
(async () => {
|
||||
for (;;) {
|
||||
await this.taskQueue.onEmpty();
|
||||
await this.onReadyToClaimTask();
|
||||
const task = await this.options.taskBroker.claim();
|
||||
this.taskQueue.add(() => this.runOneTask(task));
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
onReadyToClaimTask(): Promise<void> {
|
||||
if (this.taskQueue.pending < this.options.concurrentTasksLimit) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return new Promise(resolve => {
|
||||
// "next" event emits when a task completes
|
||||
// https://github.com/sindresorhus/p-queue#next
|
||||
this.taskQueue.on('next', () => {
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async runOneTask(task: TaskContext) {
|
||||
try {
|
||||
if (task.spec.apiVersion !== 'scaffolder.backstage.io/v1beta3') {
|
||||
|
||||
Reference in New Issue
Block a user