sidekiq-tasks 0.1.0 → 0.1.1

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: c2e154e5c7dce24a8e35fe82c1bf604aecdceb88bcdc09949bee07b250666044
4
- data.tar.gz: 79f0abe2f5d49378ab319b8c4889e35603773616a3c83e4acc12c16a3ad5bf5d
3
+ metadata.gz: ed1b4bb10d4cc9515458f41b69d8c0d347f7ed8e58e8043538465978666a4eb4
4
+ data.tar.gz: ffe569c14fcef6e479e866666c5aaae303d69f145c657612334db9f03f7bfbf6
5
5
  SHA512:
6
- metadata.gz: 46a46f7d5fe0aad48100eb29756bdf9161a6516716a2f0c2e9bfc9ee5d9ffb054ff9cd7c4d19c88032f30fcef2b4eb2253f231ebc752769b54ccd5d9b212e873
7
- data.tar.gz: 3381e43c02d4b3c7766ce818fa5b3a8a0272e1a605c2f404fc7ac758b09a420833c4fe90fa83047e9acfdf07568d0609d4168dfc9ffec1b28c5a9705a355ac9f
6
+ metadata.gz: f3f94631245ff618c1a0449160aa105122bcbfe34ce3df10ab1ac161fe44328ca0c551af0a2a635fef7a783762c2710e91c11dcd2c0fb5d1450ea83bd79a460d
7
+ data.tar.gz: 9de015b2eeacedc5104a033e07cf50dd47d760a09ef70389e32b9db36dfdc4594ceb971416f76a00f741accdb0fe6900730652cef9db1775e9ec760a0d21d496
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Changelog
2
2
 
3
+ ### [0.1.1] - 2025-02-25
4
+
5
+ - Add an environment confirmation input to the task enqueuing form.
6
+
3
7
  ### [0.1.0] - 2025-02-23
4
8
 
5
- - Initial release
9
+ - Initial release.
data/docs/task.png CHANGED
Binary file
@@ -1,6 +1,10 @@
1
1
  module Sidekiq
2
2
  module Tasks
3
3
  class Set
4
+ extend Forwardable
5
+
6
+ def_delegators :objects, :[], :each, :size, :first, :last, :empty?
7
+
4
8
  include Enumerable
5
9
 
6
10
  def self.match?(object, attributes)
@@ -15,10 +19,6 @@ module Sidekiq
15
19
  @objects = objects
16
20
  end
17
21
 
18
- def each(&block)
19
- objects.each(&block)
20
- end
21
-
22
22
  def where(attributes = {})
23
23
  reflect(objects.select { |object| self.class.match?(object, attributes) })
24
24
  end
@@ -31,22 +31,6 @@ module Sidekiq
31
31
  find_by(name: name) || raise(NotFoundError, "'#{name}' not found")
32
32
  end
33
33
 
34
- def size
35
- objects.size
36
- end
37
-
38
- def first
39
- objects[0]
40
- end
41
-
42
- def last
43
- objects[-1]
44
- end
45
-
46
- def empty?
47
- objects.empty?
48
- end
49
-
50
34
  private
51
35
 
52
36
  def reflect(objects)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Tasks
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -0,0 +1,20 @@
1
+ class EnvConfirmationController {
2
+ constructor(envConfirmationInputSelector, submitBtnSelector) {
3
+ this.envConfirmationInput = document.querySelector(envConfirmationInputSelector);
4
+ this.submitBtn = document.querySelector(submitBtnSelector);
5
+ }
6
+
7
+ connect() {
8
+ this.submitBtn.disabled = true;
9
+ this.currentEnv = this.envConfirmationInput.dataset.currentEnv;
10
+ this.envConfirmationInput.addEventListener("input", this.#handleInputChange.bind(this));
11
+ }
12
+
13
+ #handleInputChange() {
14
+ this.submitBtn.disabled = this.envConfirmationInput.value !== this.currentEnv;
15
+ }
16
+ }
17
+
18
+ document.addEventListener("DOMContentLoaded", function() {
19
+ new EnvConfirmationController("#envConfirmationInput", "#submitBtn").connect();
20
+ });
@@ -21,12 +21,16 @@ module Sidekiq
21
21
  app.get "/tasks/:name" do
22
22
  @task = find_task!(params["name"])
23
23
 
24
- erb(read_view(:_task), locals: {task: @task})
24
+ erb(read_view(:task), locals: {task: @task})
25
25
  rescue Sidekiq::Tasks::NotFoundError
26
26
  throw :halt, [404, {Rack::CONTENT_TYPE => "text/plain"}, ["Task not found"]]
27
27
  end
28
28
 
29
29
  app.post "/tasks/:name/enqueue" do
30
+ if params["env_confirmation"] != current_env
31
+ throw :halt, [400, {Rack::CONTENT_TYPE => "text/plain"}, ["Invalid confirm"]]
32
+ end
33
+
30
34
  task = find_task!(params["name"])
31
35
  args = Sidekiq::Tasks::Web::Params.new(task, params["args"]).permit!
32
36
 
@@ -10,6 +10,10 @@ module Sidekiq
10
10
  def read_view(name)
11
11
  File.read(File.join(VIEW_PATH, "#{name}.html.erb"))
12
12
  end
13
+
14
+ def current_env
15
+ ENV["RAILS_ENV"] || ENV["RACK_ENV"]
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -10,10 +10,11 @@ en:
10
10
  no_history: "No history"
11
11
  jid: "JID"
12
12
  args: "Arguments"
13
- enqueued_at: "Enqueued at"
14
- executed_at: "Executed at"
13
+ enqueued: "Enqueued"
14
+ executed: "Executed"
15
15
  task: "Task"
16
16
  desc: "Description"
17
17
  strategy: "Strategy"
18
18
  run_task: "Run task"
19
19
  enqueue: "Enqueue"
20
+ env_confirmation: "Please enter '%{current_env}' to confirm."
@@ -10,10 +10,11 @@ fr:
10
10
  no_history: "Aucun historique"
11
11
  jid: "JID"
12
12
  args: "Arguments"
13
- enqueued_at: "Mise en file d'attente le"
14
- executed_at: "Exécuté le"
13
+ enqueued: "Mise en file d'attente"
14
+ executed: "Exécuté"
15
15
  task: "Tâche"
16
16
  desc: "Description"
17
17
  strategy: "Stratégie"
18
18
  run_task: "Exécuter la tâche"
19
19
  enqueue: "Mettre en file d'attente"
20
+ env_confirmation: "Veuillez saisir '%{current_env}' pour confirmer."
@@ -1,5 +1,5 @@
1
1
  <header class="row">
2
- <div class="span col-sm-5 pull-left">
2
+ <div class="col-sm-5 pull-left">
3
3
  <h1><%= t("task") %></h1>
4
4
  </div>
5
5
  </header>
@@ -39,8 +39,8 @@
39
39
  <tr>
40
40
  <th><%= t("jid") %></th>
41
41
  <th><%= t("args") %></th>
42
- <th><%= t("enqueued_at") %></th>
43
- <th><%= t("executed_at") %></th>
42
+ <th><%= t("enqueued") %></th>
43
+ <th><%= t("executed") %></th>
44
44
  </tr>
45
45
  </thead>
46
46
  <tbody>
@@ -65,20 +65,39 @@
65
65
  <form action="<%= task_url(root_path, task) %>/enqueue" method="post">
66
66
  <%= csrf_tag %>
67
67
 
68
- <div class="container">
69
- <div class="row">
70
- <% task.args.each do |arg| %>
71
- <div class="col-md-6 mb-3">
72
- <div class="form-group">
73
- <label for="<%= arg %>" class="form-label"><%= arg %></label>
74
- <input type="text" class="form-control" name="args[<%= arg %>]" id="<%= arg %>" />
75
- </div>
68
+ <div class="row">
69
+ <% task.args.each do |arg| %>
70
+ <div class="col-sm-6">
71
+ <div class="form-group">
72
+ <label for="<%= arg %>"><%= arg %></label>
73
+ <input type="text" id="<%= arg %>" class="form-control" name="args[<%= arg %>]"/>
76
74
  </div>
77
- <% end %>
75
+ </div>
76
+ <% end %>
77
+ </div>
78
+
79
+ <div class="row">
80
+ <div class="col-sm-6">
81
+ <div class="form-group">
82
+ <label for="confirmInput">
83
+ <%= t("env_confirmation", current_env: current_env) %>
84
+ </label>
85
+
86
+ <input
87
+ type="text"
88
+ id="envConfirmationInput"
89
+ class="form-control"
90
+ name="env_confirmation"
91
+ data-current-env="<%= current_env %>"
92
+ required
93
+ />
94
+ </div>
78
95
  </div>
79
96
  </div>
80
97
 
81
- <button type="submit" class="btn btn-primary">
98
+ <button type="submit" class="btn btn-primary" id="submitBtn" disabled>
82
99
  <%= t("enqueue") %>
83
100
  </button>
84
101
  </form>
102
+
103
+ <script type="text/javascript" src="<%= root_path %>javascripts/env_confirmation.js"></script>
@@ -6,6 +6,8 @@ require "sidekiq/tasks/task"
6
6
  module Sidekiq
7
7
  module Tasks
8
8
  module Web
9
+ ASSET_PATH = File.expand_path("web/assets", __dir__).freeze
10
+
9
11
  autoload :Extension, "sidekiq/tasks/web/extension"
10
12
  autoload :Params, "sidekiq/tasks/web/params"
11
13
  end
@@ -13,6 +15,14 @@ module Sidekiq
13
15
  end
14
16
 
15
17
  if defined?(Sidekiq::Web)
18
+ Sidekiq::Web.use(
19
+ Rack::Static,
20
+ urls: ["/javascripts"],
21
+ root: File.expand_path("web/assets", __dir__),
22
+ cascade: true,
23
+ header_rules: [[:all, {"cache-control" => "private, max-age=86400"}]]
24
+ )
25
+
16
26
  Sidekiq::Web.register(Sidekiq::Tasks::Web::Extension)
17
27
  Sidekiq::Web.tabs["Tasks"] = "tasks"
18
28
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2025-02-23 00:00:00.000000000 Z
10
+ date: 2025-02-25 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -243,6 +242,7 @@ files:
243
242
  - lib/sidekiq/tasks/validations.rb
244
243
  - lib/sidekiq/tasks/version.rb
245
244
  - lib/sidekiq/tasks/web.rb
245
+ - lib/sidekiq/tasks/web/assets/javascripts/env_confirmation.js
246
246
  - lib/sidekiq/tasks/web/extension.rb
247
247
  - lib/sidekiq/tasks/web/helpers/application_helper.rb
248
248
  - lib/sidekiq/tasks/web/helpers/task_helper.rb
@@ -251,7 +251,7 @@ files:
251
251
  - lib/sidekiq/tasks/web/params.rb
252
252
  - lib/sidekiq/tasks/web/search.rb
253
253
  - lib/sidekiq/tasks/web/views/_pagination.html.erb
254
- - lib/sidekiq/tasks/web/views/_task.html.erb
254
+ - lib/sidekiq/tasks/web/views/task.html.erb
255
255
  - lib/sidekiq/tasks/web/views/tasks.html.erb
256
256
  - sig/sidekiq/tasks.rbs
257
257
  homepage: https://github.com/victorauthiat/sidekiq-tasks
@@ -261,7 +261,6 @@ metadata:
261
261
  homepage_uri: https://github.com/victorauthiat/sidekiq-tasks
262
262
  source_code_uri: https://github.com/victorauthiat/sidekiq-tasks/blob/master
263
263
  changelog_uri: https://github.com/victorauthiat/sidekiq-tasks/blob/master/CHANGELOG.md
264
- post_install_message:
265
264
  rdoc_options: []
266
265
  require_paths:
267
266
  - lib
@@ -276,8 +275,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
276
275
  - !ruby/object:Gem::Version
277
276
  version: '0'
278
277
  requirements: []
279
- rubygems_version: 3.5.22
280
- signing_key:
278
+ rubygems_version: 3.6.5
281
279
  specification_version: 4
282
280
  summary: Sidekiq extension for launching tasks.
283
281
  test_files: []