Class: DeleteInventoryWorker

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

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(restaurant_id) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/workers/delete_inventory_worker.rb', line 2

def perform(restaurant_id)
  batch_size = 1000
  offset = 0

  loop do
    ids = Inventory.where(restaurant_id: restaurant_id).offset(offset).limit(batch_size).pluck(:id)

    break if ids.blank?

    Inventory.where(id: ids).update_all(quantity_available: 0)
    offset += batch_size
  end

  InventoryTakeAway.where(restaurant_id: restaurant_id).
    in_batches(of: 1000).
    update_all quantity_available: 0
end