Skip to content

Instantly share code, notes, and snippets.

@m-nakamura145
Created November 27, 2018 03:25
Show Gist options
  • Save m-nakamura145/a8e4f63952f628e2e899b71690267b72 to your computer and use it in GitHub Desktop.
Save m-nakamura145/a8e4f63952f628e2e899b71690267b72 to your computer and use it in GitHub Desktop.
require 'worker/base_worker'
class OpenRestaurantCsvWorker < BaseWorker
sidekiq_options queue: :default, retry: 3
def self.dispatch
restaurant_ids = Restaurant.open.pluck(:id)
Sidekiq::Client.push_bulk(
'queue' => :default,
'class' => self,
'args' => restaurant_ids
)
end
def perform(restaurant_id)
restaurant = Restaurant.find(restaurant_id)
restaurant.generate_csv
end
# Bad Design
#
# def perform
# restaurants = Restaurant.open
# restaurants.each do |restaurant|
# restaurant.generate_csv
# end
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment