about summary refs log tree commit diff
path: root/streaming
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-02-05 03:19:04 +0100
committerEugen Rochko <eugen@zeonfederated.com>2017-02-05 03:19:04 +0100
commitfb6aa7ad5ce79ae0738ebf1cada0e834c33b0ef2 (patch)
treec0835a1eecf0ba434eec8984d120d21ed8000c49 /streaming
parent6cdcac1396e60286284fd8cbfe5c859050c696af (diff)
Add tracking of delay to streaming API
Diffstat (limited to 'streaming')
-rw-r--r--streaming/index.js16
1 files changed, 11 insertions, 5 deletions
diff --git a/streaming/index.js b/streaming/index.js
index 16dda5c1e..4f0df1ea5 100644
--- a/streaming/index.js
+++ b/streaming/index.js
@@ -101,7 +101,15 @@ const streamFrom = (redisClient, id, req, output, needsFiltering = false) => {
   log.verbose(`Starting stream from ${id} for ${req.accountId}`)
 
   redisClient.on('message', (channel, message) => {
-    const { event, payload } = JSON.parse(message)
+    const { event, payload, queued_at } = JSON.parse(message)
+
+    const transmit = () => {
+      const now   = new Date().getTime()
+      const delta = now - queued_at;
+
+      log.silly(`Transmitting for ${req.accountId}: ${event} ${payload} Delay: ${delta}ms`)
+      output(event, payload)
+    }
 
     // Only messages that may require filtering are statuses, since notifications
     // are already personalized and deletes do not matter
@@ -127,13 +135,11 @@ const streamFrom = (redisClient, id, req, output, needsFiltering = false) => {
             return
           }
 
-          log.silly(`Transmitting for ${req.accountId}: ${event} ${payload}`)
-          output(event, payload)
+          transmit()
         })
       })
     } else {
-      log.silly(`Transmitting for ${req.accountId}: ${event} ${payload}`)
-      output(event, payload)
+      transmit()
     }
   })