Skip to content

Commit

Permalink
Adding a daily task to catch any potentially unpublished editions tha…
Browse files Browse the repository at this point in the history
…t were scheduled for the past.

Cronjob is set up in govuk-helm-charts.
  • Loading branch information
baisa committed Mar 28, 2024
1 parent 7a551d7 commit b0bc432
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/tasks/publish_scheduled_editions.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
desc "Cronjob running daily to catch potentially unpublished editions"
task publish_scheduled_editions: :environment do
TravelAdviceEdition.with_state(:scheduled).pluck(:id).each do |id|
ScheduledPublishingWorker.new.perform(id.to_s)
end
end
30 changes: 30 additions & 0 deletions spec/tasks/publish_scheduled_editions_rake_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "rake"
describe "publish_scheduled_editions", type: :rake_task do
let(:country) { Country.find_by_slug("aruba") }
let(:task) { Rake::Task["publish_scheduled_editions"] }
let!(:robot) { create(:scheduled_publishing_robot) }

before do
Rake.application = nil
Rails.application.load_tasks
Sidekiq::Worker.clear_all
end

it "runs to publish scheduled editions that might have been left unpublished" do
edition = create(:scheduled_travel_advice_edition, country_slug: country.slug)
travel_to(2.hours.from_now)
task.invoke

expect(PublishingApiWorker.jobs.size).to eq(1)
expect(edition.reload.state).to eq("published")
end

it "does not publish editions scheduled for future publication" do
edition = create(:scheduled_travel_advice_edition, country_slug: country.slug, scheduled_publication_time: 5.hours.from_now)
travel_to(2.hours.from_now)
task.invoke

expect(PublishingApiWorker.jobs.size).to eq(0)
expect(edition.reload.state).to eq("scheduled")
end
end

0 comments on commit b0bc432

Please sign in to comment.