sidekiq-belt 2.0.1 → 2.0.2

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: cc3e263b41945c7d61098a4a7a4c7eca2cde322f3b945123e606bab80d1208dc
4
- data.tar.gz: bab878cdfcae648031fffc925dab94debddabcd32d0a618fa4da8be6f0fed000
3
+ metadata.gz: 1f2ad0b7e0a234a3f527f27a450a25c6cdf14c34387bfb38593e3637eed9eac1
4
+ data.tar.gz: a3eff6ee04902f1d4ae8e493f5d96e99038ca57511fc1720cc7343a0acd04525
5
5
  SHA512:
6
- metadata.gz: a00367b260974c366b9d9e1ac6ae7e1b10a1e3b125195199dbe601b77de1e40b2a7f87e8c830c0ad389f21667845d7cd9778d2f2d3259b48104fd689462216d6
7
- data.tar.gz: 9a231dc67e020d8a6e8e7497c7dda5ac4218cb8ced146b24a04212b3fafa832aeeeb2d0ad8e1d16b20f0a116e3df463ccfb2b1a9e45efabf7f97083c0e65322d
6
+ metadata.gz: 21012fc5d259e318c26a62765a74ab985f5ad1bff20757616672d2d37ce2f33e85b6c52318eb8b67c6fbeb51c62714f72a4e367330a3f84cc95a199c5a05c823
7
+ data.tar.gz: f04b7d0a4d5fa342d29d2220c32f05545c9ad824c5c869fcbe8e5ec80c401d0d1f7a1665e4b79cb728609ea161d3e2959decb19c43738384a526b562b17fba02
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
1
  ## [Unreleased]
2
+
3
+ ## [2.0.2] - 2025-03-23
4
+ - Dynamic args on Jobs Run
5
+
2
6
  ## [2.0.1] - 2025-03-11
3
7
  - Fix Support to Sidekiq-ent and Sidekiq-pro v8
4
8
 
data/README.md CHANGED
@@ -113,6 +113,16 @@ Sidekiq::Belt.configure do |config|
113
113
 
114
114
  config.run_jobs << { class: "CWorker", args: ["a"], group: "Etc" }
115
115
  config.run_jobs << { class: "DWorker", args: ["a"], group: "Etc" }
116
+
117
+ config.run_jobs << { class: "EWorker", args: [
118
+ { dynamic: 'text', title: 'Observation' },
119
+ { dynamic: 'integer', title: 'Number of test' },
120
+ 'fixed value A',
121
+ { dynamic: 'boolean', title: 'Boolean data' },
122
+ { dynamic: 'enum', title: 'Enum data', options: ['option1', 'option2', 'option3'], default: 'option2' },
123
+ 'fixed value B'
124
+ ], group: "Etc" }
125
+ config.run_jobs << { class: "FWorker", args: ["a"], group: "Etc" }
116
126
  end
117
127
  ```
118
128
 
@@ -20,11 +20,32 @@ module Sidekiq
20
20
  jobs
21
21
  end
22
22
 
23
- def self.run_job(job_id)
23
+ def self.dynamic_type?(arg, type)
24
+ return false unless arg.is_a?(Hash)
25
+
26
+ arg[:dynamic].to_s == type
27
+ end
28
+
29
+ def self.run_job(job_id, extra_args = {})
24
30
  job = Sidekiq::Belt.config.run_jobs[job_id.to_i]
25
31
  job.transform_keys(&:to_sym)
26
32
 
27
- Module.const_get(job[:class]).perform_async(*job.fetch(:args, []))
33
+ args = job.fetch(:args, [])
34
+
35
+ new_args = []
36
+ args.each_with_index do |arg, i|
37
+ if dynamic_type?(arg, "text") || dynamic_type?(arg, "enum")
38
+ new_args[i] = extra_args.shift
39
+ elsif dynamic_type?(arg, "integer")
40
+ new_args[i] = extra_args.shift.to_i
41
+ elsif dynamic_type?(arg, "boolean")
42
+ new_args[i] = extra_args.shift == "true"
43
+ else
44
+ new_args << arg
45
+ end
46
+ end
47
+
48
+ Module.const_get(job[:class]).perform_async(*new_args)
28
49
  end
29
50
 
30
51
  module SidekiqRunJob
@@ -36,7 +57,9 @@ module Sidekiq
36
57
  end
37
58
 
38
59
  app.post("/run_jobs/:rjid/run") do
39
- Sidekiq::Belt::Community::RunJob.run_job(route_params(:rjid).to_i)
60
+ args = url_params("args")
61
+
62
+ Sidekiq::Belt::Community::RunJob.run_job(route_params(:rjid).to_i, args)
40
63
 
41
64
  return redirect "#{root_path}run_jobs"
42
65
  end
@@ -14,10 +14,35 @@
14
14
  <% jobs.each do |job| %>
15
15
  <tr>
16
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">
17
+ <td colspan="2">
18
+ <form action="<%= root_path %>run_jobs/<%= job[:id] %>/run" class="force-run-form" method="post">
19
+ <%= '[' %>
20
+ <% (job[:args] || []).each_with_index do |arg, i| %>
21
+ <% if Sidekiq::Belt::Community::RunJob.dynamic_type?(arg, 'text') %>
22
+ <input type="text" class="form-control" name="args[]" title="<%= arg[:title] %>" required='true' placeholder="<%= arg[:title] %>" value="<%= arg[:default] %>" />
23
+ <% elsif Sidekiq::Belt::Community::RunJob.dynamic_type?(arg, 'integer') %>
24
+ <input type="number" class="form-control" name="args[]" title="<%= arg[:title] %>" required='true' placeholder="<%= arg[:title] %>" value="<%= arg[:default] %>" />
25
+ <% elsif Sidekiq::Belt::Community::RunJob.dynamic_type?(arg, 'boolean') %>
26
+ <select class="form-control" name="args[]" required='true' title="<%= arg[:title] %>" placeholder="<%= arg[:title] %>">
27
+ <option value="true" <%= arg[:default] == 'true' ? 'selected' : '' %>>true</option>
28
+ <option value="false" <%= arg[:default] == 'false' ? 'selected' : '' %>>false</option>
29
+ </select>
30
+ <% elsif Sidekiq::Belt::Community::RunJob.dynamic_type?(arg, 'enum') %>
31
+ <select class="form-control" name="args[]" required='true' title="<%= arg[:title] %>" placeholder="<%= arg[:title] %>">
32
+ <% arg[:options].each do |option| %>
33
+ <option value="<%= option %>" <%= arg[:default].to_s == option.to_s ? 'selected' : '' %>><%= option %></option>
34
+ <% end %>
35
+ </select>
36
+ <% else %>
37
+ <input type="hidden" name="args[]" value="<%= arg %>" />
38
+ <%= arg.inspect %>
39
+ <% end %>
40
+ <%= ',' if i < (job[:args] || []).size - 1 %>
41
+ <% end %>
42
+ <%= ']' %>
43
+
20
44
  <%= csrf_tag %>
45
+
21
46
  <input class="btn btn-danger" type="submit" name="run" value="<%= t('Run') %>"
22
47
  data-confirm="Run the job <%= job[:klass] %>? <%= t('AreYouSure') %>" />
23
48
  </form>
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Belt
5
- VERSION = "2.0.1"
5
+ VERSION = "2.0.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-belt
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Jeremias da Silva
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-03-12 00:00:00.000000000 Z
10
+ date: 2025-03-23 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: sidekiq