Created
November 27, 2018 03:25
-
-
Save m-nakamura145/a8e4f63952f628e2e899b71690267b72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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