Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore Responses that state claimed Requests #25

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && response.body !== null) {
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") {
torbrenner marked this conversation as resolved.
Show resolved Hide resolved
console.info(`Site ${result.from} claimed the request`)
return false
} else {
return true;
}
Expand Down