Class: EventMorningNotificationWorker
- Inherits:
-
Object
- Object
- EventMorningNotificationWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/event_morning_notification_worker.rb
Overview
Sidekiq worker: emails each event author once per day with the events
they're authoring "today" in each event's own time zone. Scheduled to
run every morning at 08:00 America/Chicago via sidekiq-scheduler — see
config/sidekiq_production_schedule.yml.
An author who is on multiple events for the day receives a single email
listing all of them (sorted by start_time) instead of one email per event.
Instance Method Summary collapse
Instance Method Details
#perform ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/workers/event_morning_notification_worker.rb', line 14 def perform todays_events = Event.where(<<~SQL.squish).includes(:authors).order(:start_time).to_a (start_time AT TIME ZONE 'UTC' AT TIME ZONE time_zone)::date = (NOW() AT TIME ZONE time_zone)::date SQL return if todays_events.empty? = Hash.new { |h, k| h[k] = [] } todays_events.each do |event| event..each { |employee| [employee] << event } end .each do |employee, events| next if employee.email.blank? WorkforceMailer.event_morning_notification(employee.id, events.map(&:id)).deliver_later end end |