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

Improve Request Queue Behavior #4 #718

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
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
10 changes: 4 additions & 6 deletions src/controller/model/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ class Endpoint extends Entity {
debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send success`);
request.resolve(result);
} catch (error) {
debug.error(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send failed, expires in ` +
debug.info(`Request Queue (${this.deviceIeeeAddress}/${this.ID}): send failed, expires in ` +
`${(request.expires - now) / 1000} seconds`);
request.reject(error);
}
Expand Down Expand Up @@ -393,16 +393,14 @@ class Endpoint extends Entity {
}
return request.send();
}
// If we already have something queued, we queue directly to avoid
// messing up the ordering too much.
// If a send is already in progress or if this is a bulk message, we also queue directly.
if (this.hasPendingRequests() || request.sendPolicy === 'bulk' || this.sendInProgress) {
// If this is a bulk message, we queue directly.
if (request.sendPolicy === 'bulk') {
debug.info(logPrefix + `queue request (${this.pendingRequests.size} / ${this.sendInProgress})))`);
return this.queueRequest(request);
}

try {
debug.info(logPrefix + `send request (queue empty)`);
debug.info(logPrefix + `send request`);
return await request.send();
} catch(error) {
// If we got a failed transaction, the device is likely sleeping.
Expand Down
Loading