Class: TimezoneWorker

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

Instance Method Summary collapse

Instance Method Details

#perform(party_id = nil) ⇒ Object



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

def perform(party_id = nil)
  if party_id
    party = Party.find(party_id)
    result = Party::RecordTimezone.new.process party
    if result.timezone_recorded?
      logger.info "[timezone] Party ID: #{party.id} -> timezone updated to #{result.timezone.name}"
    else
      logger.error "[timezone] Party ID: #{party.id} -> timezone could not be updated #{result.messages.join(', ')}"
    end
  else
    # Going to limit this to accounts updated in the last 3 months only
    party_ids = Party.where(type: %w[Contact Customer]).where(timezone_name: nil).where.not(state: 'guest').where(updated_at: 3.months.ago..).pluck(:id)
    logger.info "[timezone] Enqueuing #{party_ids.size} parties to populate timezone"
    party_ids.each do |party_id|
      TimezoneWorker.perform_async(party_id)
    end
  end
end