Skip to content

Commit

Permalink
Allow to run etl:rerun_main for a single date
Browse files Browse the repository at this point in the history
We are often asked to do this.
  • Loading branch information
AgaDufrat committed Aug 22, 2024
1 parent cb3e2a7 commit 3148c63
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/tasks/etl.rake
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ namespace :etl do
desc "Run ETL Main process across a range of dates"
task :rerun_main, %i[from to] => [:environment] do |_t, args|
from = args[:from].to_date
to = args[:to].to_date
to = args[:to]&.to_date
date_range = (from..to)
date_range.each do |date|

date_range.compact.each do |date|
puts "Running Etl::Main process for #{date}"
unless Etl::Main::MainProcessor.process(date:)
abort("Etl::Main::MainProcessor failed")
Expand Down
19 changes: 17 additions & 2 deletions spec/tasks/etl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,34 @@
create :metric, edition:, date: "2018-11-02"
create :metric, edition:, date: "2018-11-03"
Rake::Task["etl:rerun_main"].reenable
Rake::Task["etl:rerun_main"].invoke("2018-10-31", "2018-11-02")
end

it "calls Etl::Main::MainProcessor.process with each date" do
it "calls Etl::Main::MainProcessor.process with each date when a range is provided" do
Rake::Task["etl:rerun_main"].invoke("2018-10-31", "2018-11-02")

[Date.new(2018, 10, 31), Date.new(2018, 11, 1), Date.new(2018, 11, 2)].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
Rake::Task["etl:rerun_main"].invoke("2018-10-31", "2018-11-02")

[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

it "calls Etl::Main::MainProcessor.process for a single date" do
Rake::Task["etl:rerun_main"].invoke("2018-10-31")

expect(processor).to have_received(:process).once.with(Date.new(2018, 10, 31))
end

it "runs the aggregations process for a month" do
Rake::Task["etl:rerun_main"].invoke("2018-10-31")

expect(processor).to have_received(:process_aggregations).once.with(Date.new(2018, 10, 31))
end
end
end

0 comments on commit 3148c63

Please sign in to comment.