sidekiq-belt 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5e4649a97ccde536e22d2449ec678ccde0b955c0788c223fecd16487e7e9880
4
- data.tar.gz: 690b2b57d00bba771275d7143c2104f9b139fc2b883600bf4a95bfbd8b6591b5
3
+ metadata.gz: 300d0c79beb050fe381ebbc075dc66f59454eda2fa01fc0fdcbb8b1945cd2140
4
+ data.tar.gz: 875c38988275047a9fb6f3293aa68ac0c1d0ca0733b02025f20397b2980d295a
5
5
  SHA512:
6
- metadata.gz: dd3e644e8fb40e12809cd5de2744640a46df7695ad2146d7333ac09a7bcc3460168a23ff891d0e60b54fed06986240242f816f2e344d45fc86ead4c9399e350b
7
- data.tar.gz: 61dc37a8dd5f5e3b29d7410275b3c2776063ac6e2944a72b01619cbb713e8c24d55dbf21c301781865cc9b8b030d7278d1e521e115742b1d6938fc103d65d377
6
+ metadata.gz: b8c6e92eeea82ce664ee76a9670561173b927d699dc44cb3bd8bb762c29a95c8f73cfb63fa81a0ce2646896d8bcd4aeaf29cf9ea796a3edf690f3f139198b38e
7
+ data.tar.gz: bdfc0a9b7662c086c3743e6825e0356ee79f5dd17db3fd24750e9dd8b8b6e34c0ae5589ae2a7ce01ed8d61a852d6fbd1f82c89a55547abb429a43269b442d389
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.2] - 2024-01-07
4
+
5
+ - Feature to sort periodic list by class name
6
+
3
7
  ## [0.3.1] - 2023-11-01
4
8
 
5
9
  - Added style to pause button
data/README.md CHANGED
@@ -80,6 +80,41 @@ Sidekiq::Belt.use!([:failed_batch_remove])
80
80
  ```
81
81
  ![failed_batch_remove](https://github.com/dannnylo/sidekiq-belt/assets/20794/e285a8b2-4626-48e1-b04a-5190ae51d43b)
82
82
 
83
+ ### Create a list of jobs to run (sidekiq)
84
+ This feature is a manual job manager where you can list jobs. These jobs are grouped and organized in a `Run Jobs` tab.
85
+ You can easily and quickly select which job you want to run manually.
86
+
87
+ To enable this feature, pass the `run_job` option:
88
+ ```ruby
89
+ Sidekiq::Belt.use!([:run_job])
90
+ ```
91
+
92
+ ![List jobs to run](https://github.com/dannnylo/sidekiq-belt/assets/20794/ed32dac7-46e2-4c44-b3de-69983c3b990c)
93
+
94
+ To configure the list of jobs
95
+
96
+ ```ruby
97
+ Sidekiq::Belt.configure do |config|
98
+ config.run_jobs = [
99
+ { class: "ManualClearDataWorker", args: ['a'] },
100
+ { class: "ManualDoSomethingWorker", args: ['b'] },
101
+ { class: "FirstOperationalWorker", args: ['c'], group: 'Operational' },
102
+ { class: "SecondOperationalWorker", args: ['d'], group: 'Operational' },
103
+ { class: "AnotherGroupWorker", args: ['e'], group: 'Group with a long name' }
104
+ ]
105
+ end
106
+ ```
107
+ Or
108
+
109
+ ```ruby
110
+ Sidekiq::Belt.configure do |config|
111
+ config.run_jobs.push({ class: "AWorker", args: ["a"] })
112
+ config.run_jobs.push({ class: "BWorker" })
113
+
114
+ config.run_jobs << { class: "CWorker", args: ["a"], group: "Etc" }
115
+ config.run_jobs << { class: "DWorker", args: ["a"], group: "Etc" }
116
+ end
117
+ ```
83
118
 
84
119
  ## Development
85
120
 
@@ -1,18 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "sidekiq"
4
- # require_relative "feature"
4
+
5
+ require_relative "run_job"
5
6
 
6
7
  module Sidekiq
7
8
  module Belt
8
9
  module Community
9
10
  module Files
10
- def self.use!(_options = [:all])
11
- # all = options.include?(:all)
12
- # Sidekiq::Belt::Pro::Feature.load! if all || options.include?(:feature)
11
+ def self.use!(options = [:all])
12
+ Sidekiq::Belt::Community::RunJob.use! if should_use?(:run_job, options)
13
13
 
14
14
  true
15
15
  end
16
+
17
+ def self.should_use?(key, options)
18
+ options.include?(:all) || options.include?(key)
19
+ end
16
20
  end
17
21
  end
18
22
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq/web"
4
+ require "sidekiq/web/helpers"
5
+
6
+ module Sidekiq
7
+ module Belt
8
+ module Community
9
+ module RunJob
10
+ def self.list_grouped_jobs
11
+ jobs = {}
12
+ Sidekiq::Belt.config.run_jobs.each_with_index do |job, i|
13
+ job.transform_keys(&:to_sym)
14
+ job[:id] = i
15
+
16
+ jobs[job[:group].to_s] ||= []
17
+ jobs[job[:group].to_s] << job
18
+ end
19
+
20
+ jobs
21
+ end
22
+
23
+ def self.run_job(job_id)
24
+ job = Sidekiq::Belt.config.run_jobs[job_id.to_i]
25
+ job.transform_keys(&:to_sym)
26
+
27
+ Module.const_get(job[:class]).perform_async(*job.fetch(:args, []))
28
+ end
29
+
30
+ module SidekiqRunJob
31
+ def self.registered(app)
32
+ app.tabs["Run Jobs"] = "run_jobs"
33
+
34
+ app.get("/run_jobs") do
35
+ @jobs = Sidekiq::Belt::Community::RunJob.list_grouped_jobs
36
+
37
+ render(:erb, File.read(File.join(__dir__, "views/run_jobs.erb")))
38
+ end
39
+
40
+ app.post("/run_jobs/:rjid/run") do
41
+ Sidekiq::Belt::Community::RunJob.run_job(params[:rjid].to_i)
42
+
43
+ return redirect "#{root_path}run_jobs"
44
+ end
45
+ end
46
+ end
47
+
48
+ def self.use!
49
+ Sidekiq::Web.register(Sidekiq::Belt::Community::RunJob::SidekiqRunJob)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,30 @@
1
+ <% @jobs.each do |group, jobs| %>
2
+ <div class="header-container">
3
+ <h1><%= group %></h1>
4
+ </div>
5
+
6
+ <div class="table_container">
7
+ <table class="queues table table-hover table-bordered table-striped">
8
+ <thead>
9
+ <th><%= t('Class') %></th>
10
+ <th><%= t('Args') %></th>
11
+ <th><%= t('Run') %></th>
12
+ </thead>
13
+ <tbody>
14
+ <% jobs.each do |job| %>
15
+ <tr>
16
+ <td><%= job[:class] %></td>
17
+ <td><%= job[:args].inspect %></td>
18
+ <td style='width: 100px'>
19
+ <form action="<%= root_path %>run_jobs/<%= job[:id] %>/run" method="post">
20
+ <%= csrf_tag %>
21
+ <input class="btn btn-danger" type="submit" name="run" value="<%= t('Run') %>"
22
+ data-confirm="Run the job <%= job[:klass] %>? <%= t('AreYouSure') %>" />
23
+ </form>
24
+ </td>
25
+ </tr>
26
+ <% end %>
27
+ </tbody>
28
+ </table>
29
+ </div>
30
+ <% end %>
@@ -4,6 +4,7 @@ require "sidekiq"
4
4
 
5
5
  require_relative "periodic_pause"
6
6
  require_relative "periodic_run"
7
+ require_relative "periodic_sort"
7
8
 
8
9
  module Sidekiq
9
10
  module Belt
@@ -12,13 +13,16 @@ module Sidekiq
12
13
  def self.use!(options = [:all])
13
14
  return unless Sidekiq.ent?
14
15
 
15
- all = options.include?(:all)
16
-
17
- Sidekiq::Belt::Ent::PeriodicPause.use! if all || options.include?(:periodic_pause)
18
- Sidekiq::Belt::Ent::PeriodicRun.use! if all || options.include?(:periodic_run)
16
+ Sidekiq::Belt::Ent::PeriodicPause.use! if should_use?(:periodic_pause, options)
17
+ Sidekiq::Belt::Ent::PeriodicRun.use! if should_use?(:periodic_run, options)
18
+ Sidekiq::Belt::Ent::PeriodicSort.use! if should_use?(:periodic_sort, options)
19
19
 
20
20
  true
21
21
  end
22
+
23
+ def self.should_use?(key, options)
24
+ options.include?(:all) || options.include?(key)
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq/web/helpers"
4
+
5
+ module Sidekiq
6
+ module Belt
7
+ module Ent
8
+ module PeriodicSort
9
+ module SidekiqLoopsPeriodicSort
10
+ def each(&block)
11
+ @lids.map { |lid| Sidekiq::Periodic::Loop.new(lid) }.sort_by(&:klass).each(&block)
12
+ end
13
+ end
14
+
15
+ def self.use!
16
+ require("sidekiq-ent/periodic")
17
+ require("sidekiq-ent/periodic/static_loop")
18
+
19
+ Sidekiq::Periodic::LoopSet.prepend(Sidekiq::Belt::Ent::PeriodicSort::SidekiqLoopsPeriodicSort)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Belt
5
- VERSION = "0.3.1"
5
+ VERSION = "0.3.3"
6
6
  end
7
7
  end
data/lib/sidekiq/belt.rb CHANGED
@@ -19,5 +19,13 @@ module Sidekiq
19
19
  Sidekiq::Belt::Pro::Files.use!(options)
20
20
  Sidekiq::Belt::Ent::Files.use!(options)
21
21
  end
22
+
23
+ def self.configure
24
+ yield config
25
+ end
26
+
27
+ def self.config
28
+ @config ||= Struct.new(:run_jobs).new([])
29
+ end
22
30
  end
23
31
  end
@@ -14,7 +14,9 @@ module Sidekiq
14
14
 
15
15
  path_info ||= ::Rack::Utils.unescape(env["PATH_INFO"])
16
16
 
17
- Sidekiq::Config::DEFAULTS[:replace_views].fetch(path_info.to_s, []).each do |content_block|
17
+ replace_views = Sidekiq::Config::DEFAULTS[:replace_views] || {}
18
+
19
+ replace_views.fetch(path_info.to_s, []).each do |content_block|
18
20
  content_block.call(content)
19
21
  end
20
22
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Jeremias da Silva
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-01 00:00:00.000000000 Z
11
+ date: 2024-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq
@@ -42,9 +42,12 @@ files:
42
42
  - lib/sidekiq-belt.rb
43
43
  - lib/sidekiq/belt.rb
44
44
  - lib/sidekiq/belt/community/files.rb
45
+ - lib/sidekiq/belt/community/run_job.rb
46
+ - lib/sidekiq/belt/community/views/run_jobs.erb
45
47
  - lib/sidekiq/belt/ent/files.rb
46
48
  - lib/sidekiq/belt/ent/periodic_pause.rb
47
49
  - lib/sidekiq/belt/ent/periodic_run.rb
50
+ - lib/sidekiq/belt/ent/periodic_sort.rb
48
51
  - lib/sidekiq/belt/pro/failed_batch_remove.rb
49
52
  - lib/sidekiq/belt/pro/files.rb
50
53
  - lib/sidekiq/belt/version.rb
@@ -73,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
76
  - !ruby/object:Gem::Version
74
77
  version: '0'
75
78
  requirements: []
76
- rubygems_version: 3.4.10
79
+ rubygems_version: 3.5.3
77
80
  signing_key:
78
81
  specification_version: 4
79
82
  summary: This Ruby gem enhances the capabilities of Sidekiq, Sidekiq Pro, and Sidekiq