Skip to content

Commit 83edff4

Browse files
committed
Add EnqueueLocationPositionUpdaterJob
This adds a job which enqueues a `LocationPositionUpdaterJob` for each location with an address but without a position. It's set up to run at midnight, in a low priority queue. Jira-Issue: MAV-6379
1 parent b583eff commit 83edff4

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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

app/models/concerns/address_concern.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff 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

config/sidekiq.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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

0 commit comments

Comments
 (0)