-
Notifications
You must be signed in to change notification settings - Fork 11
/
rescue_scheduled_publishing_service.rb
48 lines (38 loc) · 1.17 KB
/
rescue_scheduled_publishing_service.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class RescueScheduledPublishingService
include Callable
def initialize(edition_id:)
@edition_id = edition_id
end
def call
edition = nil
Edition.transaction do
edition = Edition.lock.find_current(id: edition_id)
update_status(edition)
create_timeline_entry(edition)
end
notify_editors(edition)
end
private
attr_reader :edition_id
def update_status(edition)
raise "Expected edition to be scheduled" unless edition.scheduled?
AssignEditionStatusService.call(edition,
user: edition.status.created_by,
state: :failed_to_publish,
record_edit: false,
status_details: edition.status.details)
edition.save!
end
def create_timeline_entry(edition)
TimelineEntry.create_for_status_change(
entry_type: :scheduled_publishing_failed,
status: edition.status,
)
end
def notify_editors(edition)
edition.editors.each do |editor|
ScheduledPublishMailer.failure_email(editor, edition, edition.status)
.deliver_later
end
end
end