Skip to content

Instantly share code, notes, and snippets.

@glenbray
Last active February 11, 2020 11:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glenbray/fc70180810159fe3c91bdf5035d41ec7 to your computer and use it in GitHub Desktop.
Save glenbray/fc70180810159fe3c91bdf5035d41ec7 to your computer and use it in GitHub Desktop.
extract address jobs
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
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