Skip to content

Commit

Permalink
feat: revert create message on unoapi campaign with perform later
Browse files Browse the repository at this point in the history
  • Loading branch information
clairton committed Jul 28, 2024
1 parent 1738abe commit 45ee68a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/jobs/campaign_message_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class CampaignMessageJob < ApplicationJob
queue_as :high
queue_as :low

# rubocop:disable Metrics/AbcSize
def perform(account_id, inbox_id, campaign_id, content, audience)
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/oneoff_unoapi_campaign_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class OneoffUnoapiCampaignJob < ApplicationJob
queue_as :high
queue_as :low

def perform(campaign_id)
campaign = Campaign.find(campaign_id)
Expand Down
4 changes: 3 additions & 1 deletion app/models/campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def trigger!
def one_off_unoapi
return unless inbox.channel_type == 'Channel::Whatsapp' && inbox&.channel&.provider == 'unoapi'

OneoffUnoapiCampaignJob.perfom_later(id)
Whatsapp::OneoffUnoapiCampaignService.new(campaign: self).perform
end

def load_attributes_created_by_db_triggers
Expand All @@ -73,6 +73,8 @@ def load_attributes_created_by_db_triggers
# We can't use reload because it will clear the previous changes, which we need for the dispatcher
obj_from_db = self.class.find(id)
self[:display_id] = obj_from_db[:display_id]
rescue ActiveRecord::RecordNotFound
Rails.logger.error("Ignore raise ActiveRecord::RecordNotFound on load campaign id #{id}")
end

def validate_campaign_inbox
Expand Down
2 changes: 1 addition & 1 deletion spec/jobs/campaign_message_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
phone_number,
campaign.message
)
.on_queue('high')
.on_queue('low')
end

context 'when the job is triggered on a new message' do
Expand Down
2 changes: 0 additions & 2 deletions spec/services/whatsapp/oneoff_unoapi_campaign_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@
it 'send messages to contacts in the audience and marks the campaign completed' do
allow(CampaignMessageJob).to receive(:perform_later)
allow(CampaignMessageJob).to receive(:set).and_return(CampaignMessageJob)

unoapi_campaign_service.perform
expect(campaign.reload.completed?).to be true

expect(CampaignMessageJob)
.to have_received(:perform_later)
.with(
Expand Down

0 comments on commit 45ee68a

Please sign in to comment.