-
Notifications
You must be signed in to change notification settings - Fork 11
/
schedule_publish_service.rb
41 lines (33 loc) · 1.13 KB
/
schedule_publish_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
class SchedulePublishService
include Callable
def initialize(edition, user, scheduling, **)
@edition = edition
@user = user
@scheduling = scheduling
end
def call
update_edition(scheduling, user)
create_or_update_publish_intent
schedule_to_publish(scheduling)
end
private
attr_reader :edition, :user, :scheduling
def update_edition(scheduling, user)
updater = Versioning::RevisionUpdater.new(edition.revision, user)
updater.assign(proposed_publish_time: nil)
EditDraftEditionService.call(edition, user, revision: updater.next_revision)
AssignEditionStatusService.call(edition,
user: user,
state: :scheduled,
status_details: scheduling)
edition.save!
end
def create_or_update_publish_intent
payload = Payload.new(edition).intent_payload
GdsApi.publishing_api.put_intent(edition.base_path, payload)
end
def schedule_to_publish(scheduling)
ScheduledPublishingJob.set(wait_until: scheduling.publish_time)
.perform_later(edition.id)
end
end