Class: Restaurants::VoucherOfferWorker

Inherits:
ApplicationWorker show all
Defined in:
app/workers/restaurants/voucher_offer_worker.rb

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(restaurant_id, previous_restaurant_id = nil) ⇒ Object

Parameters:

  • restaurant_id (Integer)
  • previous_restaurant_id (Integer, nil) (defaults to: nil)


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

def perform(restaurant_id, previous_restaurant_id = nil)
  restaurant = Restaurant.find_by(id: restaurant_id)
  return if restaurant.blank?

  ticket_groups = restaurant.ticket_groups
  if ticket_groups.blank?
    restaurant.voucher_offer_date = nil
  else
    voucher_offer_date = ticket_groups.max_by(&:selling_end_date).selling_end_date
    restaurant.voucher_offer_date = voucher_offer_date
  end

  restaurant.save

  send_update_voucher_offer_event(restaurant, previous_restaurant_id)

  GenerateCompactRestaurantsWorker.perform_async(restaurant_id)
end