From 3617abac31f9b4f1aae7babd424a0272a3a24056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20Krupin=CC=81ski?= Date: Thu, 14 Dec 2017 12:52:58 +0100 Subject: [PATCH 1/3] Return queue length with metadata --- lib/actions/queue/GetQueueMetadata.js | 5 +++-- lib/model/queue/AzuriteQueueResponse.js | 5 +++-- lib/model/queue/Queue.js | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/actions/queue/GetQueueMetadata.js b/lib/actions/queue/GetQueueMetadata.js index db5b015..0adb5a1 100644 --- a/lib/actions/queue/GetQueueMetadata.js +++ b/lib/actions/queue/GetQueueMetadata.js @@ -10,11 +10,12 @@ class GetQueueMetadata { process(request, res) { const queue = QueueManager.getQueueAndMessage({ queueName: request.queueName }).queue, metaProps = queue.metaProps, + queueLength = queue.getLength(), response = new AzuriteQueueResponse(); - response.addMetaProps(metaProps); + response.addMetaProps(metaProps, queueLength); res.set(response.httpProps); res.status(200).send(); } } -module.exports = new GetQueueMetadata(); \ No newline at end of file +module.exports = new GetQueueMetadata(); diff --git a/lib/model/queue/AzuriteQueueResponse.js b/lib/model/queue/AzuriteQueueResponse.js index 5bdaacf..1f05984 100644 --- a/lib/model/queue/AzuriteQueueResponse.js +++ b/lib/model/queue/AzuriteQueueResponse.js @@ -17,11 +17,12 @@ class AzuriteQueueResponse { } } - addMetaProps(metaProps) { + addMetaProps(metaProps, queueLength) { Object.keys(metaProps).forEach((key) => { this.addHttpProperty(`x-ms-meta-${key}`, metaProps[key]); }); + this.addHttpProperty(`x-ms-approximate-messages-count`, queueLength); } } -module.exports = AzuriteQueueResponse; \ No newline at end of file +module.exports = AzuriteQueueResponse; diff --git a/lib/model/queue/Queue.js b/lib/model/queue/Queue.js index 104b233..4e12ace 100644 --- a/lib/model/queue/Queue.js +++ b/lib/model/queue/Queue.js @@ -122,6 +122,10 @@ class Queue { index: index }; } + + getLength() { + return this.messages.length; + } } -module.exports = Queue; \ No newline at end of file +module.exports = Queue; From 09c9d25f422b633edf7794e14d8f85c51174590d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20Krupin=CC=81ski?= Date: Thu, 14 Dec 2017 13:39:15 +0100 Subject: [PATCH 2/3] minor refactoring --- lib/actions/queue/GetQueueMetadata.js | 3 ++- lib/model/queue/AzuriteQueueResponse.js | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/actions/queue/GetQueueMetadata.js b/lib/actions/queue/GetQueueMetadata.js index 0adb5a1..318eb6e 100644 --- a/lib/actions/queue/GetQueueMetadata.js +++ b/lib/actions/queue/GetQueueMetadata.js @@ -12,7 +12,8 @@ class GetQueueMetadata { metaProps = queue.metaProps, queueLength = queue.getLength(), response = new AzuriteQueueResponse(); - response.addMetaProps(metaProps, queueLength); + response.addMetaProps(metaProps); + response.addHttpProperty(`x-ms-approximate-messages-count`, queueLength); res.set(response.httpProps); res.status(200).send(); } diff --git a/lib/model/queue/AzuriteQueueResponse.js b/lib/model/queue/AzuriteQueueResponse.js index 1f05984..766210d 100644 --- a/lib/model/queue/AzuriteQueueResponse.js +++ b/lib/model/queue/AzuriteQueueResponse.js @@ -21,7 +21,6 @@ class AzuriteQueueResponse { Object.keys(metaProps).forEach((key) => { this.addHttpProperty(`x-ms-meta-${key}`, metaProps[key]); }); - this.addHttpProperty(`x-ms-approximate-messages-count`, queueLength); } } From 997c57b04ad0e1c5bea35d6af6a876673cd017bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leszek=20Krupin=CC=81ski?= Date: Thu, 14 Dec 2017 19:40:00 +0100 Subject: [PATCH 3/3] reverted to original method signature --- lib/model/queue/AzuriteQueueResponse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/model/queue/AzuriteQueueResponse.js b/lib/model/queue/AzuriteQueueResponse.js index 766210d..6b5b828 100644 --- a/lib/model/queue/AzuriteQueueResponse.js +++ b/lib/model/queue/AzuriteQueueResponse.js @@ -17,7 +17,7 @@ class AzuriteQueueResponse { } } - addMetaProps(metaProps, queueLength) { + addMetaProps(metaProps) { Object.keys(metaProps).forEach((key) => { this.addHttpProperty(`x-ms-meta-${key}`, metaProps[key]); });