sidekiq-belt 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e1d58a367e0ec0d41fb826a95a5b61cc59c6431fd5d50f235786cb3521e1ac69
4
- data.tar.gz: 2cf1947d6e5ca5b54fe9989ec5a30e09923474412bce3d65475a13aa693d29fd
3
+ metadata.gz: 300d0c79beb050fe381ebbc075dc66f59454eda2fa01fc0fdcbb8b1945cd2140
4
+ data.tar.gz: 875c38988275047a9fb6f3293aa68ac0c1d0ca0733b02025f20397b2980d295a
5
5
  SHA512:
6
- metadata.gz: 8f8b2a0e54438fc416a638c3de38bcdccd187eea0363863d33ec04a2aa97dfc97983548445ab1f7f15148837123dccdad11cc47274ac59287e473c1223189b78
7
- data.tar.gz: 6467a245b671d70c33b759b579f1ea12d4adf48c0bde494979e39d8c6663468859fc147f9f9add16ac967a9249e3ae6ac50476078fb59629167a14d5aeffa610
6
+ metadata.gz: b8c6e92eeea82ce664ee76a9670561173b927d699dc44cb3bd8bb762c29a95c8f73cfb63fa81a0ce2646896d8bcd4aeaf29cf9ea796a3edf690f3f139198b38e
7
+ data.tar.gz: bdfc0a9b7662c086c3743e6825e0356ee79f5dd17db3fd24750e9dd8b8b6e34c0ae5589ae2a7ce01ed8d61a852d6fbd1f82c89a55547abb429a43269b442d389
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 %>
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Belt
5
- VERSION = "0.3.2"
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
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.2
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: 2024-02-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,6 +42,8 @@ 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
@@ -74,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
76
  - !ruby/object:Gem::Version
75
77
  version: '0'
76
78
  requirements: []
77
- rubygems_version: 3.4.10
79
+ rubygems_version: 3.5.3
78
80
  signing_key:
79
81
  specification_version: 4
80
82
  summary: This Ruby gem enhances the capabilities of Sidekiq, Sidekiq Pro, and Sidekiq