Skip to content

Instantly share code, notes, and snippets.

@skwp
Created February 17, 2015 19:40
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 skwp/3697890cdc2284a72cd2 to your computer and use it in GitHub Desktop.
Save skwp/3697890cdc2284a72cd2 to your computer and use it in GitHub Desktop.
class BatchStatusPaginator
include Sidekiq::Paginator
def initialize(page_size=25)
@page_size = page_size
end
# Get all batch statuses
def all
current_page, total_size, items = batches(1)
(1..total_size).map do |page|
status_page(page)
end.flatten
end
# Get a single page of batch statuses
def status_page(page)
current_page, total_size, items = batches(page)
items.map { |batch| status(batch) }.compact
end
private
def status(batch)
begin
Sidekiq::Batch::Status.new(batch.first)
rescue Sidekiq::Batch::NoSuchBatch
nil
end
end
def batches(page)
page("batches", page, @page_size, :reverse => true)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment