Change heartbeat backoff logic

Send first two heartbeats at 0 and 30 secs, then increase the backoff
interval 1min per call until a maximun of 5min.
This commit is contained in:
Alberto Fernández Capel 2018-01-24 16:03:43 +00:00
parent dd2e9d7431
commit e42d1f9b13

View file

@ -6,9 +6,9 @@ define [
], (moment, App) ->
CACHE_KEY = "mbEvents"
# Keep track of when the editing session started and when we should
# send the next heartbeat so we can space them properly
sessionStart = new Date()
# keep track of how many heartbeats we've sent so we can calculate how
# long wait until the next one
heartbeatsSent = 0
nextHeartbeat = new Date()
send = (category, action, attributes = {})->
@ -47,12 +47,16 @@ define [
@_sendEditingSessionHeartbeat(segmentation)
sessionDuration = (new Date().getTime() - sessionStart.getTime())/1000
heartbeatsSent++
backoffSecs = switch
when sessionDuration < 60 then 30
when sessionDuration < 300 then 60
else 300
# send two first heartbeats at 0 and 30s then increase the backoff time
# 1min per call until we reach 5 min
backoffSecs = if heartbeatsSent <= 2
30
else if heartbeatsSent <= 6
(heartbeatsSent - 2) * 60
else
300
nextHeartbeat = moment().add(backoffSecs, 'seconds').toDate()