Skip to content

Commit

Permalink
Update syncing logic with message drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
luciajanikova committed Sep 20, 2023
1 parent 45f211e commit 6528427
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/message_drafts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def submit
end

def submit_all
@message_drafts.each(&:submit)
Govbox::SubmitMultipleMessageDraftsJob.perform_later(@message_drafts.to_a)
end

def destroy
Expand Down
5 changes: 5 additions & 0 deletions app/jobs/govbox/finish_message_drafts_submit_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Govbox::FinishMessageDraftsSubmitJob < ApplicationJob
def perform(batch, params)
Govbox::SyncBoxJob.set(wait: 3.minutes).perform_later(batch.properties[:box])
end
end
4 changes: 2 additions & 2 deletions app/jobs/govbox/submit_message_draft_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Govbox::SubmitMessageDraftJob < ApplicationJob
def perform(message_draft, upvs_client: UpvsEnvironment.upvs_client)
def perform(message_draft, schedule_sync: true, upvs_client: UpvsEnvironment.upvs_client)
message_draft_data = {
posp_id: message_draft.metadata["posp_id"],
posp_version: message_draft.metadata["posp_version"],
Expand All @@ -19,7 +19,7 @@ def perform(message_draft, upvs_client: UpvsEnvironment.upvs_client)
success, response_status = sktalk_api.receive_and_save_to_outbox(message_draft_data)
if success
message_draft.metadata["status"] = "submitted"
Govbox::SyncBoxJob.set(wait: 3.minutes).perform_later(message_draft.thread.folder.box)
Govbox::SyncBoxJob.set(wait: 3.minutes).perform_later(message_draft.thread.folder.box) if schedule_sync
else
handle_submit_fail(message_draft, response_status)
end
Expand Down
7 changes: 7 additions & 0 deletions app/jobs/govbox/submit_multiple_message_drafts_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Govbox::SubmitMultipleMessageDraftsJob < ApplicationJob
def perform(message_drafts, jobs_batch: GoodJob::Batch.new)
message_drafts.each { |message_draft| message_draft.submit(jobs_batch: jobs_batch) }

jobs_batch.enqueue(on_finish: Govbox::FinishMessageDraftsSubmitJob, box: message_draft.thread.folder.box)
end
end
8 changes: 6 additions & 2 deletions app/models/message_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ def self.create_message_reply(original_message: , author:)
)
end

def submit
def submit(jobs_batch: nil)
return false unless submittable?

Govbox::SubmitMessageDraftJob.perform_later(self)
if jobs_batch
jobs_batch.add { Govbox::SubmitMessageDraftJob.perform_later(self, schedule_sync: false) }
else
Govbox::SubmitMessageDraftJob.perform_later(self)
end

metadata["status"] = "being_submitted"
save!
Expand Down

0 comments on commit 6528427

Please sign in to comment.