Class: SmartServicesNotificationWorker

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

Overview

Sidekiq worker: smart services notification.

Instance Method Summary collapse

Instance Method Details

#performObject

Runs the job.

Returns:

  • (Object)

    the result



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
# File 'app/workers/smart_services_notification_worker.rb', line 10

def perform
  SupportCase.services.where(service_date: Time.current, service_time: Time.current..2.hours.from_now).find_each do |sc|
    sc.with_lock do
      next if sc.notified_at.present?

      msg = "SmartService scheduled in the next 2 hours. Case #{sc.case_number}. "
      msg += if (address = sc.service_address)
               "Service provided in #{address.city}, #{address.state_code}."
             else
               "Service address unknown"
             end
      # SMS sent to JL's phone number
      TwilioClient.send_message(to: sc.field_technician_cell,
                                body: msg)
      sc.update!(notified_at: Time.current)
    end
  end

  SupportCase.services.where(service_date: 1.working.day.from_now).find_each do |sc|
    sc.with_lock do
      next if sc.customer_24h_notification.present?

      sc.send_24h_customer_notification
    end
  end
end