Created
February 17, 2015 19:40
-
-
Save skwp/3697890cdc2284a72cd2 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
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