Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(699) Allow Content Block schedule to be edited #9699

Merged
merged 8 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module ContentBlockManager
module Concerns
module Dequeueable
extend ActiveSupport::Concern

def dequeue_all_previously_queued_editions(content_block_edition)
content_block_edition.document.editions.where(state: :scheduled).find_each do |edition|
next if content_block_edition.id == edition.id

ContentBlockManager::SchedulePublishingWorker.dequeue(edition)
edition.supersede!
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module ContentBlockManager
class PublishEditionService
class PublishingFailureError < StandardError; end

include Concerns::Dequeueable

def call(edition)
publish_with_rollback(edition)
end
Expand All @@ -28,6 +30,7 @@ def publish_with_rollback(content_block_edition)
},
)
ContentBlockManager::SchedulePublishingWorker.dequeue(content_block_edition) if content_block_edition.scheduled?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContentBlockManager::SchedulePublishingWorker.dequeue(content_block_edition) if content_block_edition.scheduled?

do you think this line could be part of the dequeuing concern? or is the dequeuing concern already doing this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or could it have it's own named function to show what it's doing like dequeue_current_edition_if_previously_scheduled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good plan! Have done 👍

dequeue_all_previously_queued_editions(content_block_edition)
publish_publishing_api_edition(content_id:)
update_content_block_document_with_latest_edition(content_block_edition)
content_block_edition.public_send(:publish!)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module ContentBlockManager
class ScheduleEditionService
include Concerns::Dequeueable

def initialize(schema)
@schema = schema
end
Expand All @@ -15,6 +17,7 @@ def call(edition, scheduled_publication_params)
end

private

def schedule_with_rollback
raise ArgumentError, "Local database changes not given" unless block_given?

Expand All @@ -26,6 +29,8 @@ def schedule_with_rollback
else
content_block_edition.schedule!
end

dequeue_all_previously_queued_editions(content_block_edition)
ContentBlockManager::SchedulePublishingWorker.queue(content_block_edition)
end
end
Expand Down
21 changes: 21 additions & 0 deletions lib/engines/content_block_manager/features/schedule_object.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ Feature: Schedule a content object
Then I should see the scheduled date on the object
And there should only be one job scheduled

@disable-sidekiq-test-mode
Scenario: GDS Editor publishes a new version of a previously scheduled content object
When I am updating a content block
Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
When I am updating a content block
And I choose to publish the change now
And I accept and publish
Then there should be no jobs scheduled

@disable-sidekiq-test-mode
Scenario: GDS Editor schedules a new version of a previously scheduled content block
When I am updating a content block
Then I am asked when I want to publish the change
And I schedule the change for 7 days in the future
When I click to view the content block
And I click to edit the schedule
And I schedule the change for 5 days in the future
When I click to view the content block
Then there should only be one job scheduled

Scenario: A scheduled content object is published
When I am updating a content block
Then I am asked when I want to publish the change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,22 @@ class ContentBlockManager::PublishEditionServiceTest < ActiveSupport::TestCase
assert_nil document.live_edition_id
end
end

it "supersedes any previously scheduled editions" do
scheduled_editions = create_list(:content_block_edition, 2,
document:,
scheduled_publication: 7.days.from_now,
state: "scheduled")

scheduled_editions.each do |scheduled_edition|
ContentBlockManager::SchedulePublishingWorker.expects(:dequeue).with(scheduled_edition)
end

ContentBlockManager::PublishEditionService.new.call(edition)

scheduled_editions.each do |scheduled_edition|
assert scheduled_edition.reload.superseded?
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class ContentBlockManager::ScheduleEditionServiceTest < ActiveSupport::TestCase
end

setup do
ContentBlockManager::ContentBlock::Schema.stubs(:find_by_block_type)
.returns(schema)
stub_publishing_api_has_embedded_content(content_id:, total: 0, results: [], order: ContentBlockManager::GetHostContentItems::DEFAULT_ORDER)
end

Expand Down Expand Up @@ -66,6 +68,29 @@ class ContentBlockManager::ScheduleEditionServiceTest < ActiveSupport::TestCase
.call(edition, scheduled_publication_params)
end

it "supersedes any previously scheduled editions" do
scheduled_editions = create_list(:content_block_edition, 2,
document: edition.document,
scheduled_publication: 7.days.from_now,
state: "scheduled")

ContentBlockManager::SchedulePublishingWorker.expects(:queue).with do |expected_edition|
expected_edition.id = edition.id
end

scheduled_editions.each do |scheduled_edition|
ContentBlockManager::SchedulePublishingWorker.expects(:dequeue).with(scheduled_edition)
end

ContentBlockManager::ScheduleEditionService
.new(schema)
.call(edition, scheduled_publication_params)

scheduled_editions.each do |scheduled_edition|
assert scheduled_edition.reload.superseded?
end
end

it "does not persist the changes if the Worker request fails" do
exception = GdsApi::HTTPErrorResponse.new(
422,
Expand Down
Loading