sidekiq-belt 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +64 -0
- data/lib/sidekiq/belt/community/files.rb +10 -4
- data/lib/sidekiq/belt/community/run_job.rb +54 -0
- data/lib/sidekiq/belt/community/top_label.rb +29 -0
- data/lib/sidekiq/belt/community/views/run_jobs.erb +30 -0
- data/lib/sidekiq/belt/version.rb +1 -1
- data/lib/sidekiq/belt.rb +16 -0
- data/lib/sidekiq/web_action_helper.rb +17 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb4d769018b00b231892ae9852e6fd7d8c51074f6752332fa46ce6e606d68ba7
|
4
|
+
data.tar.gz: 9b05f6c1a3a505c7e6028bd6248f07ed7964a307129d7f8fc3206d96817c2b61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7c1f6c6ef57da7f982bc3c1c2cfc8ffec1982ed0030a37f9b829fc9ff4e2dcabd1f606283d81014e668fa1063504f6b2dcf77837b45939a3654f91d5f99354b
|
7
|
+
data.tar.gz: 6cb88155712149c79268f4f0a27a49c81e60eccc890c6eed0a1a9c29b9697ff561d9730f333c16b428bbf3ca0b50a2857da1439e7b049f367b8511b3b269af3a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -80,6 +80,70 @@ 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
|
+
```
|
118
|
+
|
119
|
+
### Add to your web sidekiq a top label by enviroment (sidekiq)
|
120
|
+
|
121
|
+
This feature adds a little line on top of Sidekiq web that shows a configurable message.
|
122
|
+
|
123
|
+
![Top Page Development](https://github.com/dannnylo/sidekiq-belt/assets/20794/b1e2f6c2-a257-4172-92ec-09c61511334b)
|
124
|
+
![Top Page Production](https://github.com/dannnylo/sidekiq-belt/assets/20794/8e64d0e8-dcb2-42ee-b184-67d2f0b2cf6f)
|
125
|
+
|
126
|
+
To enable this feature, pass the `top_label` option:
|
127
|
+
```ruby
|
128
|
+
Sidekiq::Belt.use!([:top_label])
|
129
|
+
```
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
Sidekiq::Belt.configure do |config|
|
133
|
+
config.top_label = {
|
134
|
+
production: {
|
135
|
+
background_color: 'red',
|
136
|
+
text: 'Be carefull',
|
137
|
+
color: 'white'
|
138
|
+
},
|
139
|
+
development: {
|
140
|
+
background_color: 'green',
|
141
|
+
text: 'You are safe!',
|
142
|
+
color: 'white'
|
143
|
+
}
|
144
|
+
}
|
145
|
+
end
|
146
|
+
```
|
83
147
|
|
84
148
|
## Development
|
85
149
|
|
@@ -1,18 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "sidekiq"
|
4
|
-
|
4
|
+
|
5
|
+
require_relative "run_job"
|
6
|
+
require_relative "top_label"
|
5
7
|
|
6
8
|
module Sidekiq
|
7
9
|
module Belt
|
8
10
|
module Community
|
9
11
|
module Files
|
10
|
-
def self.use!(
|
11
|
-
|
12
|
-
|
12
|
+
def self.use!(options = [:all])
|
13
|
+
Sidekiq::Belt::Community::RunJob.use! if should_use?(:run_job, options)
|
14
|
+
Sidekiq::Belt::Community::TopLabel.use! if should_use?(:top_label, options)
|
13
15
|
|
14
16
|
true
|
15
17
|
end
|
18
|
+
|
19
|
+
def self.should_use?(key, options)
|
20
|
+
options.include?(:all) || options.include?(key)
|
21
|
+
end
|
16
22
|
end
|
17
23
|
end
|
18
24
|
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,29 @@
|
|
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 TopLabel
|
10
|
+
def self.use!
|
11
|
+
Sidekiq::WebActionHelper.change_layout do |content|
|
12
|
+
top_label = (Sidekiq::Belt.config.top_label || {}).fetch(Sidekiq::Belt.env, {})
|
13
|
+
|
14
|
+
html = "<div class='container-fluid'
|
15
|
+
style='background: #{::Rack::Utils.escape_html(top_label.fetch(:background_color, "red"))};
|
16
|
+
text-align: center;
|
17
|
+
color: #{::Rack::Utils.escape_html(top_label.fetch(:color, "white"))};'>
|
18
|
+
#{::Rack::Utils.escape_html(top_label[:text].to_s)}
|
19
|
+
</div>"
|
20
|
+
unless top_label.empty?
|
21
|
+
content.gsub!('<div class="container-fluid">',
|
22
|
+
"#{html} <div class='container-fluid'>")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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 %>
|
data/lib/sidekiq/belt/version.rb
CHANGED
data/lib/sidekiq/belt.rb
CHANGED
@@ -19,5 +19,21 @@ 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, :top_label).new([], {})
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.env
|
32
|
+
(Sidekiq.default_configuration[:environment] ||
|
33
|
+
ENV["APP_ENV"] ||
|
34
|
+
ENV["RAILS_ENV"] ||
|
35
|
+
ENV["RACK_ENV"] ||
|
36
|
+
"development").to_sym
|
37
|
+
end
|
22
38
|
end
|
23
39
|
end
|
@@ -22,6 +22,23 @@ module Sidekiq
|
|
22
22
|
|
23
23
|
super(engine, content, options)
|
24
24
|
end
|
25
|
+
|
26
|
+
def self.change_layout(&block)
|
27
|
+
Sidekiq::Config::DEFAULTS[:layout_changes] ||= []
|
28
|
+
Sidekiq::Config::DEFAULTS[:layout_changes] << block
|
29
|
+
end
|
30
|
+
|
31
|
+
def _render
|
32
|
+
content = super
|
33
|
+
|
34
|
+
layout_changes = Sidekiq::Config::DEFAULTS[:layout_changes] || []
|
35
|
+
|
36
|
+
layout_changes.each do |content_block|
|
37
|
+
content_block.call(content)
|
38
|
+
end
|
39
|
+
|
40
|
+
content
|
41
|
+
end
|
25
42
|
end
|
26
43
|
|
27
44
|
Sidekiq::WebAction.prepend(Sidekiq::WebActionHelper)
|
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.
|
4
|
+
version: 0.3.4
|
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-
|
11
|
+
date: 2024-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -42,6 +42,9 @@ 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/top_label.rb
|
47
|
+
- lib/sidekiq/belt/community/views/run_jobs.erb
|
45
48
|
- lib/sidekiq/belt/ent/files.rb
|
46
49
|
- lib/sidekiq/belt/ent/periodic_pause.rb
|
47
50
|
- lib/sidekiq/belt/ent/periodic_run.rb
|
@@ -74,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
77
|
- !ruby/object:Gem::Version
|
75
78
|
version: '0'
|
76
79
|
requirements: []
|
77
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.5.3
|
78
81
|
signing_key:
|
79
82
|
specification_version: 4
|
80
83
|
summary: This Ruby gem enhances the capabilities of Sidekiq, Sidekiq Pro, and Sidekiq
|