Skip to content

Commit

Permalink
fix: ignore responses that state claimed requests
Browse files Browse the repository at this point in the history
  • Loading branch information
torbrenner committed Sep 21, 2023
1 parent 73edfdb commit 216fcae
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions core/cql/src/beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class Beam implements RequestTarget {
console.log(`Requesting results from ${this.sites.length} sites through ${this.key}`)
for (let i = 1; i <= this.sites.length; i++) {
let retryCounter = 0;
let response = await firstValueFrom(this.client.get<Array<BeamResult>>(
let response: HttpResponse<BeamResult[]> = await firstValueFrom(this.client.get<Array<BeamResult>>(
this.url.toString() + `tasks/${this.currentTask?.id}?wait_count=${i}`,
{
observe: "response",
Expand Down Expand Up @@ -117,12 +117,15 @@ export class Beam implements RequestTarget {
);
if (response.status == 200) {
console.log(`Received new partial result for query ${this.currentTask?.id} with results from ${i} sites.`)
i = (response.body) ? response.body.length : i
let receivedTask = (response.body != undefined) ? response.body[0].task : "";
if (receivedTask.indexOf(this.currentTask?.id) != -1) {
this.resultsReceived(response)
} else {
console.warn(`Throwing away response for old query ${receivedTask} in favor of new query ${this.currentTask?.id}`)
if (response.body != undefined) {
i = response.body
.filter(test => test.status !== "claimed").length;
let receivedTask = response.body[0].task;
if (this.currentTask != undefined && receivedTask.indexOf(this.currentTask.id) != -1) {
this.resultsReceived(response)
} else {
console.warn(`Throwing away response for old query ${receivedTask} in favor of new query ${this.currentTask?.id}`)
}
}
}
// add a little delay between requests so diagrams won't change to fast
Expand All @@ -140,6 +143,9 @@ export class Beam implements RequestTarget {
if (result.status == "permfailed" || result.status == "tempfailed") {
console.warn(`Site ${result.from} returned status ${result.status}. Therefore ignoring their result!`)
return false;
} else if (result.status == "claimed") {
console.info(`Site ${result.from} claimed the request`)
return false
} else {
return true;
}
Expand Down

0 comments on commit 216fcae

Please sign in to comment.