File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ class EnqueueLocationPositionUpdaterJob < ApplicationJob
4+ queue_as :third_party_data_imports
5+
6+ def perform
7+ ids = Location . where ( position : nil ) . has_address . ids
8+ LocationPositionUpdaterJob . perform_bulk ( ids . zip )
9+ end
10+ end
Original file line number Diff line number Diff line change @@ -18,6 +18,16 @@ module AddressConcern
1818 has_one :local_authority_from_postcode ,
1919 through : :local_authority_postcode ,
2020 source : :local_authority
21+
22+ scope :has_address ,
23+ -> do
24+ where ( "address_line_1 IS NOT NULL AND address_line_1 <> ''" )
25+ . or ( where ( "address_line_2 IS NOT NULL AND address_line_2 <> ''" ) )
26+ . or ( where ( "address_town IS NOT NULL AND address_town <> ''" ) )
27+ . or (
28+ where ( "address_postcode IS NOT NULL AND address_postcode <> ''" )
29+ )
30+ end
2131 end
2232
2333 def address_parts
Original file line number Diff line number Diff line change 3939 description : Send vaccination confirmation emails to parents
4040
4141 # Nightly
42+ EnqueueLocationPositionUpdaterJob :
43+ cron : " 0 0 * * *"
44+ description :
45+ Enqueue jobs to fetch latitude and longitude for locations with addresses but no position
4246 RemoveImportCSVJob :
4347 cron : " 0 1 * * *"
4448 description : Remove CSV data from old cohort and immunisation imports
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ describe EnqueueLocationPositionUpdaterJob do
4+ describe "#perform" do
5+ subject ( :perform_now ) { described_class . perform_now }
6+
7+ let! ( :location_with_address_no_position ) do
8+ create ( :community_clinic , position : nil )
9+ end
10+
11+ let! ( :location_with_position ) { create ( :community_clinic ) }
12+
13+ let! ( :location_without_address ) do
14+ create ( :community_clinic , :without_address )
15+ end
16+
17+ it "enqueues jobs for locations with address but no position" do
18+ expect { perform_now } . to enqueue_sidekiq_job (
19+ LocationPositionUpdaterJob
20+ ) . with ( location_with_address_no_position . id )
21+ end
22+
23+ it "does not enqueue jobs for locations with position" do
24+ expect { perform_now } . not_to enqueue_sidekiq_job (
25+ LocationPositionUpdaterJob
26+ ) . with ( location_with_position . id )
27+ end
28+
29+ it "does not enqueue jobs for locations without address" do
30+ expect { perform_now } . not_to enqueue_sidekiq_job (
31+ LocationPositionUpdaterJob
32+ ) . with ( location_without_address . id )
33+ end
34+ end
35+ end
You can’t perform that action at this time.
0 commit comments