-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a daily task to catch any potentially unpublished editions tha…
…t were scheduled for the past. Cronjob is set up in govuk-helm-charts.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |