Skip to content

Commit

Permalink
Support max_retries > 0 in Replay mode
Browse files Browse the repository at this point in the history
o Never reset retries in Replay mode to avoid replaying the same
  timeframe again and again when GNIP is unstable
  • Loading branch information
Laurent Farcy committed Jul 6, 2016
1 parent a6b10fd commit 7730a79
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/powertrack/streaming/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,10 @@ def track_once(options, retrier)
# get the message type and its (optional) level
m_type, m_level = message_type(raw)

# reset retries when some (valid) data are received
if retrier.retrying? && m_level != :error
# reset retries when some (valid) data are received but not in replay
# mode where we don't want to retry on the same timeframe again and
# again when GNIP periodically fails
if !@replay && retrier.retrying? && m_level != :error
logger.info "Resetting retries..."
retrier.reset!
end
Expand Down Expand Up @@ -423,7 +425,10 @@ def track_once(options, retrier)
logger.info "Disconnected after #{retrier.retries} retries"
disconnected = true

if closed
resp_status = http_client.response_header.status

# stop the stream if required so or the replay is simply over
if closed || (@replay && resp_status == DEFAULT_OK_RESPONSE_STATUS)
# close immediately if required
wait_til_defers_finish_and_stop(stop_timeout)
# tell the retrier the tracking is over
Expand All @@ -432,7 +437,7 @@ def track_once(options, retrier)
# cancel the periodic close watcher
close_watcher.cancel

resp_status = http_client.response_header.status || DEFAULT_OK_RESPONSE_STATUS
resp_status ||= DEFAULT_OK_RESPONSE_STATUS
resp_error = http_client.error
resp_body = http_client.response

Expand Down
2 changes: 1 addition & 1 deletion test/test_track_stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def track_simple_stream(replay)
on_activity: on_activity,
on_system: on_system,
close_now: close_now,
max_retries: replay ? 0 : 2,
max_retries: 2,
fake_disconnections: replay ? nil : 20,
from: from,
to: to)
Expand Down

0 comments on commit 7730a79

Please sign in to comment.