From 657f08502aa3a2ddf6b66187ffd564c61a5bcac5 Mon Sep 17 00:00:00 2001 From: Chris Seaton Date: Fri, 30 Sep 2022 14:49:01 +0100 Subject: [PATCH 1/3] Use bundle exec to run example files (#5552) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When showing a junior how to explore how Sidekiq works, we noticed that if you’re running from the source directory, you’ll need to use bundle exec to get the gem on the load path. Co-authored-by: Musa Kurel Co-authored-by: Musa Kurel --- examples/por.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/por.rb b/examples/por.rb index a89943ab..73763170 100644 --- a/examples/por.rb +++ b/examples/por.rb @@ -1,9 +1,9 @@ require "sidekiq" # Start up sidekiq via -# ./bin/sidekiq -r ./examples/por.rb +# bundle exec bin/sidekiq -r ./examples/por.rb # and then you can open up an IRB session like so: -# irb -r ./examples/por.rb +# bundle exec irb -r ./examples/por.rb # where you can then say # PlainOldRuby.perform_async "like a dog", 3 # From d424e453282314ea25f484739c72697b5a4d8f82 Mon Sep 17 00:00:00 2001 From: fatkodima Date: Tue, 4 Oct 2022 00:24:55 +0300 Subject: [PATCH 2/3] Add pagination to "Busy" page (#5556) --- lib/sidekiq/paginator.rb | 8 ++++++++ lib/sidekiq/web/application.rb | 3 +++ web/views/busy.erb | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/sidekiq/paginator.rb b/lib/sidekiq/paginator.rb index a5605cab..0de7cb64 100644 --- a/lib/sidekiq/paginator.rb +++ b/lib/sidekiq/paginator.rb @@ -43,5 +43,13 @@ module Sidekiq end end end + + def page_items(items, pageidx = 1, page_size = 25) + current_page = pageidx.to_i < 1 ? 1 : pageidx.to_i + pageidx = current_page - 1 + starting = pageidx * page_size + items = items.to_a + [current_page, items.size, items[starting, page_size]] + end end end diff --git a/lib/sidekiq/web/application.rb b/lib/sidekiq/web/application.rb index be66feb4..236c66d5 100644 --- a/lib/sidekiq/web/application.rb +++ b/lib/sidekiq/web/application.rb @@ -74,6 +74,9 @@ module Sidekiq end get "/busy" do + @count = (params["count"] || 100).to_i + (@current_page, @total_size, @workset) = page_items(workset, params["page"], @count) + erb(:busy) end diff --git a/web/views/busy.erb b/web/views/busy.erb index 47091041..9295ee4a 100644 --- a/web/views/busy.erb +++ b/web/views/busy.erb @@ -96,6 +96,11 @@

<%= t('Jobs') %>

+ <% if @workset.size > 0 && @total_size > @count %> +
+ <%= erb :_paging, locals: { url: "#{root_path}busy" } %> +
+ <% end %>
@@ -109,7 +114,7 @@ <%= t('Arguments') %> <%= t('Started') %> - <% workset.each do |process, thread, msg| %> + <% @workset.each do |process, thread, msg| %> <% job = Sidekiq::JobRecord.new(msg['payload']) %> <%= process %> From 7037533e8f39cc1d3c1e305140da7667c6efe38f Mon Sep 17 00:00:00 2001 From: fatkodima Date: Tue, 4 Oct 2022 00:51:35 +0300 Subject: [PATCH 3/3] Speedup iterating over `WorkSet` (#5559) --- lib/sidekiq/api.rb | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/sidekiq/api.rb b/lib/sidekiq/api.rb index 6863bb16..f9988451 100644 --- a/lib/sidekiq/api.rb +++ b/lib/sidekiq/api.rb @@ -1103,24 +1103,31 @@ module Sidekiq def each(&block) results = [] + procs = nil + all_works = nil + Sidekiq.redis do |conn| - procs = conn.sscan_each("processes").to_a - procs.sort.each do |key| - valid, workers = conn.pipelined { |pipeline| - pipeline.exists?(key) + procs = conn.sscan_each("processes").to_a.sort + + all_works = conn.pipelined do |pipeline| + procs.each do |key| pipeline.hgetall("#{key}:work") - } - next unless valid - workers.each_pair do |tid, json| - hsh = Sidekiq.load_json(json) - p = hsh["payload"] - # avoid breaking API, this is a side effect of the JSON optimization in #4316 - hsh["payload"] = Sidekiq.load_json(p) if p.is_a?(String) - results << [key, tid, hsh] end end end + procs.zip(all_works).each do |key, workers| + workers.each_pair do |tid, json| + next if json.empty? + + hsh = Sidekiq.load_json(json) + p = hsh["payload"] + # avoid breaking API, this is a side effect of the JSON optimization in #4316 + hsh["payload"] = Sidekiq.load_json(p) if p.is_a?(String) + results << [key, tid, hsh] + end + end + results.sort_by { |(_, _, hsh)| hsh["run_at"] }.each(&block) end