Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix db_poller fetching so it does not use the saved last_sent_id on i… #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/deimos/utils/db_poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,37 @@ def process_updates
# by the producer itself.
loop do
Deimos.config.logger.debug("Polling #{@producer.topic}, batch #{batch_count + 1}")
batch = fetch_results(time_from, time_to).to_a
batch = if batch_count == 0
# set min_id to 0 on the initial fetch of results
fetch_results(time_from, time_to, 0).to_a
else
fetch_results(time_from, time_to).to_a
end
break if batch.empty?

batch_count += 1
process_batch(batch)
message_count += batch.size
time_from = last_updated(batch.last)
end
# Update last_sent to time_to for this set of updates
@info.last_sent = time_to
@info.save!
Deimos.config.logger.info("Poll #{@producer.topic} complete at #{time_to} (#{message_count} messages, #{batch_count} batches}")
end

# @param time_from [ActiveSupport::TimeWithZone]
# @param time_to [ActiveSupport::TimeWithZone]
# @return [ActiveRecord::Relation]
def fetch_results(time_from, time_to)
def fetch_results(time_from, time_to, min_id=nil)
id = @producer.config[:record_class].primary_key
quoted_timestamp = ActiveRecord::Base.connection.quote_column_name(@config.timestamp_column)
quoted_id = ActiveRecord::Base.connection.quote_column_name(id)
min_id = min_id.present? ? min_id : @info.last_sent_id
@producer.poll_query(time_from: time_from,
time_to: time_to,
column_name: @config.timestamp_column,
min_id: @info.last_sent_id).
min_id: min_id).
limit(BATCH_SIZE).
order("#{quoted_timestamp}, #{quoted_id}")
end
Expand Down