make sure buffered heartbeats keep correct ordering
This commit is contained in:
parent
8aa92e51bf
commit
dcfaf16a96
1 changed files with 16 additions and 1 deletions
|
@ -317,9 +317,10 @@ let s:VERSION = '5.0.1'
|
||||||
|
|
||||||
function! s:GetHeartbeatsJson()
|
function! s:GetHeartbeatsJson()
|
||||||
let arr = []
|
let arr = []
|
||||||
|
let loop_count = 1
|
||||||
for heartbeat in s:heartbeats_buffer
|
for heartbeat in s:heartbeats_buffer
|
||||||
let heartbeat_str = '{"entity": "' . s:JsonEscape(heartbeat.entity) . '", '
|
let heartbeat_str = '{"entity": "' . s:JsonEscape(heartbeat.entity) . '", '
|
||||||
let heartbeat_str = heartbeat_str . '"timestamp": ' . heartbeat.time . ', '
|
let heartbeat_str = heartbeat_str . '"timestamp": ' . s:OrderTime(heartbeat.time, loop_count) . ', '
|
||||||
let heartbeat_str = heartbeat_str . '"is_write": '
|
let heartbeat_str = heartbeat_str . '"is_write": '
|
||||||
if heartbeat.is_write
|
if heartbeat.is_write
|
||||||
let heartbeat_str = heartbeat_str . 'true'
|
let heartbeat_str = heartbeat_str . 'true'
|
||||||
|
@ -331,11 +332,25 @@ let s:VERSION = '5.0.1'
|
||||||
endif
|
endif
|
||||||
let heartbeat_str = heartbeat_str . '}'
|
let heartbeat_str = heartbeat_str . '}'
|
||||||
let arr = arr + [heartbeat_str]
|
let arr = arr + [heartbeat_str]
|
||||||
|
let loop_count = loop_count + 1
|
||||||
endfor
|
endfor
|
||||||
let s:heartbeats_buffer = []
|
let s:heartbeats_buffer = []
|
||||||
return '[' . join(arr, ',') . ']'
|
return '[' . join(arr, ',') . ']'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:OrderTime(time_str, loop_count)
|
||||||
|
" Add a milisecond to a:time.
|
||||||
|
" Time prevision doesn't matter, but order of heartbeats does.
|
||||||
|
if !a:time_str =~ "\."
|
||||||
|
let millisecond = printf('%d', a:loop_count)
|
||||||
|
while strlen(millisecond) < 6
|
||||||
|
let millisecond = '0' . millisecond
|
||||||
|
endwhile
|
||||||
|
return a:time_str . '.' . millisecond
|
||||||
|
endif
|
||||||
|
return a:time_str
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:GetLastHeartbeat()
|
function! s:GetLastHeartbeat()
|
||||||
if !s:last_heartbeat.last_activity_at || localtime() - s:last_heartbeat.last_activity_at > s:local_cache_expire
|
if !s:last_heartbeat.last_activity_at || localtime() - s:last_heartbeat.last_activity_at > s:local_cache_expire
|
||||||
if !filereadable(s:data_file)
|
if !filereadable(s:data_file)
|
||||||
|
|
Loading…
Reference in a new issue