Skip to content

Commit

Permalink
Merge pull request #2232 from alphagov/samsimpson1/rerun-list-rake
Browse files Browse the repository at this point in the history
Add rake task to run ETL Main process for a list of dates
  • Loading branch information
samsimpson1 authored Feb 5, 2025
2 parents 4b7a228 + 47645a2 commit 2595fb7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/tasks/etl.rake
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,23 @@ namespace :etl do
Etl::Main::MainProcessor.process_aggregations(date:)
end
end

desc "Run ETL Main process for a list of dates"
task rerun_main_list: :environment do |_t, args|
dates = args.extras.map(&:to_date)

dates.compact.each do |date|
puts "Running Etl::Main process for #{date}"
unless Etl::Main::MainProcessor.process(date:)
abort("Etl::Main::MainProcessor failed")
end
puts "finished running Etl::Main for #{date}"
end

month_ends = dates.map(&:end_of_month).uniq
month_ends.each do |date|
puts "Running monthly and search aggregations for #{date}"
Etl::Main::MainProcessor.process_aggregations(date:)
end
end
end
31 changes: 31 additions & 0 deletions spec/tasks/etl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,35 @@
end
end
end

describe "rake etl:rerun_main_list" do
let!(:processor) do
class_double(
Etl::Main::MainProcessor,
process: true,
process_aggregations: true,
).as_stubbed_const
end

before do
edition = create :edition, date: "2018-10-03"
create :metric, edition:, date: "2018-10-30"
create :metric, edition:, date: "2018-10-31"
create :metric, edition:, date: "2018-11-03"
Rake::Task["etl:rerun_main_list"].reenable
Rake::Task["etl:rerun_main_list"].invoke("2018-10-30", "2018-10-31", "2018-11-03")
end

it "calls Etl::Main::MainProcessor.process with each date" do
[Date.new(2018, 10, 30), Date.new(2018, 10, 31), Date.new(2018, 11, 3)].each do |date|
expect(processor).to have_received(:process).once.with(date:)
end
end

it "runs the aggregations process for each month in the range" do
[Date.new(2018, 10, 31), Date.new(2018, 11, 30)].each do |date|
expect(processor).to have_received(:process_aggregations).once.with(date:)
end
end
end
end

0 comments on commit 2595fb7

Please sign in to comment.