File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
jobs/better_together/geography
models/better_together/infrastructure Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module BetterTogether
4+ module Geography
5+ class GeocodingJob < ApplicationJob # rubocop:todo Style/Documentation
6+ queue_as :geocoding
7+
8+ def perform ( geocodable )
9+ geocodable . geocode
10+ geocodable . save
11+ end
12+ end
13+ end
14+ end
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ class Building < Structure
3232
3333 after_create :ensure_floor
3434
35- after_validation :geocode , if : -> ( obj ) { obj . address . present? and ( obj . address_changed? || obj . geocoded? ) }
35+ after_create :schedule_address_geocoding
36+ after_update :schedule_address_geocoding
3637
3738 translates :name
3839 translates :description , backend : :action_text
@@ -57,6 +58,15 @@ def ensure_floor
5758 floors . create ( name : 'Ground' )
5859 end
5960
61+ def schedule_address_geocoding
62+ return unless should_geocode?
63+ BetterTogether ::Geography ::GeocodingJob . perform_later ( self )
64+ end
65+
66+ def should_geocode?
67+ address . present? and ( address_changed? or !geocoded? )
68+ end
69+
6070 def select_option_title
6171 "#{ name } (#{ slug } )"
6272 end
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ default: &default
33 queues :
44 - default
55 - mailers
6+ - es_indexing
7+ - geocoding
68
79development :
810 << : *default
You can’t perform that action at this time.
0 commit comments