Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add per_page for server middleware, paginate wating queue #207

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/qless/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ def current_page
end
end

PAGE_SIZE = 25
def per_page
@per_page ||= begin
Integer(params[:per_page])
rescue
20
end
end

def pagination_values
start = (current_page - 1) * PAGE_SIZE
[start, start + PAGE_SIZE]
start = (current_page - 1) * per_page
[start, start + per_page]
end

def paginated(qless_object, method, *args)
Expand Down Expand Up @@ -180,7 +187,8 @@ def strftime(t)

jobs = []
if tab == 'waiting'
jobs = queue.peek(20)
start, finish = pagination_values
jobs = queue.peek(finish)[start..finish]
elsif filtered_tabs.include?(tab)
jobs = paginated(queue.jobs, tab).map { |jid| client.jobs[jid] }
end
Expand Down