Просмотр исходного кода

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.
Alberto Fernández Capel 8 лет назад
Родитель
Сommit
e42d1f9b13
1 измененных файлов с 12 добавлено и 8 удалено
  1. 12 8
      services/web/public/coffee/main/event.coffee

+ 12 - 8
services/web/public/coffee/main/event.coffee

@@ -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()