7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'app/workers/communication_worker.rb', line 7
def perform(communication_ids = [])
communication_ids = [communication_ids].compact.flatten
if communication_ids.present?
logger.info "Communication Worker processing communication id(s): #{communication_ids.join(',')}"
Communication.non_campaign.where(state: 'queued').where(id: communication_ids).find_each do |communication|
logger.info "Found queued communication id : #{communication.id}, attempting release"
communication.release
logger.info "Done sending communication id : #{communication.id}, new state is #{communication.state}, status is #{communication.status_message}"
end
else
communication_ids = Communication.non_campaign.where(state: 'queued').where('transmit_at IS NULL or transmit_at <= ?',
Time.current).order(:created_at).pluck(:id)
communication_ids.each do |cid|
logger.info "Communication worker enqueuing communication worker with communication id #{cid}"
CommunicationWorker.perform_async(cid)
end
end
end
|