Skip to content

Commit

Permalink
Fixed message when visit not found for geocoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Mar 1, 2018
1 parent f956194 commit 1bb48e7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion app/jobs/ahoy/geocode_v2_job.rb
Expand Up @@ -13,7 +13,6 @@ def perform(visit_token, ip)

if location
data = {
visit_token: visit_token,
country: location.try(:country).presence,
region: location.try(:state).presence,
city: location.try(:city).presence,
Expand Down
7 changes: 4 additions & 3 deletions lib/ahoy/database_store.rb
Expand Up @@ -25,14 +25,15 @@ def track_event(data)
end

def geocode(data)
data = slice_data(visit_model, data.except(:visit_token))
visit_token = data.delete(:visit_token)
data = slice_data(visit_model, data)
if defined?(Mongoid::Document) && visit_model < Mongoid::Document
# upsert since visit might not be found due to eventual consistency
visit_model.where(visit_token: ahoy.visit_token).find_one_and_update({"$set": data}, {upsert: true})
visit_model.where(visit_token: visit_token).find_one_and_update({"$set": data}, {upsert: true})
elsif visit
visit.update_attributes(data)
else
Ahoy.log "Visit for geocode not found: #{data[:visit_token]}"
Ahoy.log "Visit for geocode not found: #{visit_token}"
end
end

Expand Down
6 changes: 5 additions & 1 deletion lib/ahoy/tracker.rb
Expand Up @@ -65,7 +65,11 @@ def geocode(data)
if exclude?
debug "Geocode excluded"
else
@store.geocode(data.select { |_, v| v })
data = {
visit_token: visit_token
}.merge(data).select { |_, v| v }

@store.geocode(data)
true
end
rescue => e
Expand Down

0 comments on commit 1bb48e7

Please sign in to comment.