fix(core): Fix task runner sending too many offers (#12415)

This commit is contained in:
Tomi Turtiainen
2025-01-02 10:16:28 +02:00
committed by GitHub
parent a484ea160b
commit 4498e35192
2 changed files with 160 additions and 67 deletions

View File

@@ -174,9 +174,11 @@ export abstract class TaskRunner extends EventEmitter {
sendOffers() {
this.deleteStaleOffers();
const offersToSend =
this.maxConcurrency -
(Object.values(this.openOffers).length + Object.values(this.runningTasks).length);
if (!this.canSendOffers) {
return;
}
const offersToSend = this.maxConcurrency - (this.openOffers.size + this.runningTasks.size);
for (let i = 0; i < offersToSend; i++) {
// Add a bit of randomness so that not all offers expire at the same time
@@ -255,11 +257,12 @@ export abstract class TaskRunner extends EventEmitter {
}
hasOpenTasks() {
return Object.values(this.runningTasks).length < this.maxConcurrency;
return this.runningTasks.size < this.maxConcurrency;
}
offerAccepted(offerId: string, taskId: string) {
if (!this.hasOpenTasks()) {
this.openOffers.delete(offerId);
this.send({
type: 'runner:taskrejected',
taskId,
@@ -267,6 +270,7 @@ export abstract class TaskRunner extends EventEmitter {
});
return;
}
const offer = this.openOffers.get(offerId);
if (!offer) {
this.send({