Last active
February 11, 2020 11:29
-
-
Save glenbray/fc70180810159fe3c91bdf5035d41ec7 to your computer and use it in GitHub Desktop.
extract address jobs
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
class Scheduled::ExtractAddressesBatchJob | |
include Sidekiq::Worker | |
sidekiq_options lock: :until_and_while_executing | |
def perform | |
sites = Site | |
.select(:id) | |
.addresses_not_checked | |
.limit(10_000) | |
sites.find_in_batches do |batch| | |
site_ids = batch.pluck(:id) | |
site_ids.each_slice(500) do |slice| | |
ExtractAddressesJob.perform_later(slice) | |
end | |
timestamp = DateTime.now | |
Site | |
.where(id: site_ids) | |
.update_all(last_address_check_at: timestamp, updated_at: timestamp) | |
end | |
end | |
end |
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
class ExtractAddressesJob < ApplicationJob | |
queue_as :default | |
def perform(page_ids) | |
sites = Site.where(id: site_ids).includes(:pages) | |
ExtractAddresses.process(sites) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment