Class: CampaignCommunicationWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/workers/campaign_communication_worker.rb

Instance Method Summary collapse

Instance Method Details

#perform(communication_ids = []) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/workers/campaign_communication_worker.rb', line 8

def perform(communication_ids = [])
  communication_ids = [communication_ids].compact.flatten
  if communication_ids.present?
    logger.info "Campaign Communication Worker processing communication id(s): #{communication_ids.join(',')}"
    Communication.campaign_only.where(state: 'queued').where(id: communication_ids).each do |communication|
      logger.info "Found queued campaign communication id : #{communication.id}, attempting release"
      communication.release
      logger.info "Done sending campaign communication id : #{communication.id}, new state is #{communication.state}, status is #{communication.status_message}"
    end
  else
    # Enqueuing mode
    communication_ids = Communication.campaign_only.where(state: 'queued').where('transmit_at IS NULL or transmit_at <= ?',
                                                                                 Time.current).order('id asc').pluck(:id)
    communication_ids.each do |cid|
      logger.info "Campaign Communication worker enqueuing campaign communication worker with communication id #{cid}"
      CampaignCommunicationWorker.perform_async(cid)
    end
  end
end