sidekiq-tasks 0.1.3 → 0.1.4

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: b815ea42b8cc57ba73f3711e735fda709755b75c282e200dc18ab5287eadfdd6
4
- data.tar.gz: 3e3e652e28ae9ee632452e89bab64bf34db9d4961a6b1eb7e5ff05914cfca3e3
3
+ metadata.gz: 9f8d4001fa7c85be52975408343d261f87b68da263508e6a97e23d2327685121
4
+ data.tar.gz: a0e978fd7ea7a0959571d9c635cbecf667d319f14e3424cbd68bf90f4f936db6
5
5
  SHA512:
6
- metadata.gz: 53cb0abf54140641134acaf350bf51bf989f3b8d454359fe2b3f32a9ad1937d6257b06de3a000e602f3a63a217e475c4229c23712a88987731a27cab73485d29
7
- data.tar.gz: 854ef40802df6e3d3cd6eda1eae39df3aff31efc8d1e82c69ae201b1ca3576060fcd9dd3bb71e7bfc6b1c8275f6db7169c61fcaabd84da18be121b3a9c0e55d6
6
+ metadata.gz: 83bfda60244fda1c62876d2ea6f8a0d61f32e558c0492fd28ac4936d32fc601969c5b676ac18b21d9533796b4e21de9f57ff509b65acb253d0b5d635f52b2249
7
+ data.tar.gz: 15ec2cf69ea14409f2c852c3fc3c82ffb49dabaedaccccf93084b86d88099d328f6a2b8f03e57578acff9a2272d2782a4653dc42d46c8f76625ad287bf5ab0fb
data/.rubocop.yml CHANGED
@@ -33,7 +33,7 @@ Metrics/PerceivedComplexity:
33
33
 
34
34
  Naming/FileName:
35
35
  Exclude:
36
- - lib/sidekiq/sidekiq-tasks.rb
36
+ - lib/sidekiq-tasks.rb
37
37
 
38
38
  Naming/MemoizedInstanceVariableName:
39
39
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Changelog
2
2
 
3
+ ### [0.1.4] - 2025-03-23
4
+
5
+ - Fix gem load error by moving the entrypoint to the correct path.
6
+ - Support enabling/disabling all tasks in a namespace with a magic comment.
7
+ - Improve task search to allow more flexible and intuitive matching.
8
+ - Fix deprecation warning by avoiding direct access to `params` (Sidekiq 8 compatibility).
9
+
3
10
  ### [0.1.3] - 2025-03-22
4
11
 
5
12
  - Change required Ruby version to 3.0.0.
data/README.md CHANGED
@@ -47,7 +47,7 @@ By default, it comes with the `Sidekiq::Tasks::Strategies::RakeTask` strategy, w
47
47
  > - **`TaskFromLib`** Only tasks from the `lib` folder are loaded.
48
48
  > - **`EnableWithComment`** Only tasks explicitly enabled with a magic comment are loaded.
49
49
 
50
- Example of an available task in `lib/tasks/my_task.rake`:
50
+ Example of an enabled task in `lib/tasks/my_task.rake`:
51
51
 
52
52
  ```ruby
53
53
  # sidekiq-tasks:enable
@@ -56,7 +56,22 @@ task :my_task do
56
56
  end
57
57
  ```
58
58
 
59
- You can also use `DisableWithComment` rule to selectively **exclude** tasks. (see [strategies configuration](#strategies-configuration))
59
+ Enable all tasks within a namespace:
60
+
61
+ ```ruby
62
+ # sidekiq-tasks:enable
63
+ namespace :my_namespace do
64
+ task :my_task do
65
+ puts "my_task"
66
+ end
67
+
68
+ task :another_task do
69
+ puts "another_task"
70
+ end
71
+ end
72
+ ```
73
+
74
+ You can also use `DisableWithComment` rule to selectively **disable** tasks. (see [strategies configuration](#strategies-configuration))
60
75
  It works similarly to `EnableWithComment`, but with inverted logic. Example of a disabled task:
61
76
 
62
77
  ```ruby
@@ -9,7 +9,12 @@ module Sidekiq
9
9
 
10
10
  def self.match?(object, attributes)
11
11
  attributes.any? do |attribute, value|
12
- [nil, ""].include?(value) || object.public_send(attribute)&.match?(value)
12
+ next true if [nil, ""].include?(value)
13
+
14
+ object_value = object.public_send(attribute).to_s.downcase.gsub(/[^a-z0-9]/, "")
15
+ search_fragments = value.to_s.downcase.gsub(/[^a-z0-9\s]/, "").split
16
+
17
+ search_fragments.all? { |fragment| object_value.include?(fragment) }
13
18
  end
14
19
  end
15
20
 
@@ -4,11 +4,19 @@ module Sidekiq
4
4
  module Rules
5
5
  class EnableWithComment < Base
6
6
  def respected?(task)
7
- lines = relevant_lines(task)
7
+ file, line_number = task.locations.first.split(":")
8
+ line_number = line_number.to_i
8
9
 
9
- return false if lines.first.match?(/namespace/)
10
+ lines = read_file_lines(file)
10
11
 
11
- lines.any? { |line| line.strip.match?(magic_comment_regex) }
12
+ return false if lines.nil?
13
+
14
+ return true if task_has_magic_comment?(lines, line_number)
15
+
16
+ namespace_line_index = find_namespace_line_index(lines, task)
17
+ return false unless namespace_line_index
18
+
19
+ namespace_has_magic_comment?(lines, namespace_line_index)
12
20
  end
13
21
 
14
22
  protected
@@ -19,13 +27,32 @@ module Sidekiq
19
27
 
20
28
  private
21
29
 
22
- def relevant_lines(task)
23
- file, start_line = task.locations.first.split(":")
24
- start_line_counting_desc = start_line.to_i > 2 ? start_line.to_i - 3 : 0
25
- File.read(file).split("\n")[start_line_counting_desc..start_line_counting_desc + 1].reverse
30
+ def read_file_lines(file)
31
+ File.read(file).split("\n")
26
32
  rescue Errno::ENOENT
27
33
  raise ArgumentError, "File '#{file}' not found"
28
34
  end
35
+
36
+ def task_has_magic_comment?(lines, task_line)
37
+ context_range = (task_line - 3..task_line).to_a.select { |i| i >= 0 }
38
+ context_range.reverse.any? do |i|
39
+ lines[i]&.strip&.match?(magic_comment_regex)
40
+ end
41
+ end
42
+
43
+ def find_namespace_line_index(lines, task)
44
+ namespace = namespace_name(task)
45
+ lines.find_index { |line| line.strip.match?(/^namespace\s+:#{Regexp.escape(namespace)}/) }
46
+ end
47
+
48
+ def namespace_has_magic_comment?(lines, namespace_line_index)
49
+ comment_line = lines[namespace_line_index - 1]&.strip
50
+ comment_line&.match?(magic_comment_regex)
51
+ end
52
+
53
+ def namespace_name(task)
54
+ task.name.split(":").first
55
+ end
29
56
  end
30
57
  end
31
58
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sidekiq
4
4
  module Tasks
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.4"
6
6
  end
7
7
  end
@@ -15,7 +15,7 @@ module Sidekiq
15
15
  app.helpers(Sidekiq::Tasks::Web::Helpers::PaginationHelper)
16
16
 
17
17
  app.get "/tasks" do
18
- @search = Sidekiq::Tasks::Web::Search.new(params.transform_keys(&:to_sym))
18
+ @search = Sidekiq::Tasks::Web::Search.new(fetch_params(:count, :page, :filter))
19
19
 
20
20
  erb(read_view(:tasks), locals: {search: @search})
21
21
  end
@@ -29,12 +29,12 @@ module Sidekiq
29
29
  end
30
30
 
31
31
  app.post "/tasks/:name/enqueue" do
32
- if params["env_confirmation"] != current_env
32
+ if fetch_param("env_confirmation") != current_env
33
33
  throw :halt, [400, {Rack::CONTENT_TYPE => "text/plain"}, ["Invalid confirm"]]
34
34
  end
35
35
 
36
36
  task = find_task!(env["rack.route_params"][:name])
37
- args = Sidekiq::Tasks::Web::Params.new(task, params["args"]).permit!
37
+ args = Sidekiq::Tasks::Web::Params.new(task, fetch_param("args")).permit!
38
38
 
39
39
  task.enqueue(args)
40
40
 
@@ -12,6 +12,18 @@ module Sidekiq
12
12
  def current_env
13
13
  ENV["RAILS_ENV"] || ENV["RACK_ENV"]
14
14
  end
15
+
16
+ def fetch_param(key)
17
+ if Sidekiq::Tasks::Web::SIDEKIQ_GTE_8_0_0
18
+ url_params(key.to_s)
19
+ else
20
+ params[key.to_s]
21
+ end
22
+ end
23
+
24
+ def fetch_params(*keys)
25
+ keys.to_h { |key| [key.to_sym, fetch_param(key)] }
26
+ end
15
27
  end
16
28
  end
17
29
  end
@@ -7,6 +7,7 @@ module Sidekiq
7
7
 
8
8
  ROOT = File.expand_path("../../../web", File.dirname(__FILE__))
9
9
  SIDEKIQ_GTE_7_3_0 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("7.3.0")
10
+ SIDEKIQ_GTE_8_0_0 = Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("8.0.0")
10
11
  end
11
12
  end
12
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-tasks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-03-22 00:00:00.000000000 Z
11
+ date: 2025-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -238,7 +238,7 @@ files:
238
238
  - README.md
239
239
  - Rakefile
240
240
  - docs/task.png
241
- - lib/sidekiq/sidekiq-tasks.rb
241
+ - lib/sidekiq-tasks.rb
242
242
  - lib/sidekiq/tasks.rb
243
243
  - lib/sidekiq/tasks/config.rb
244
244
  - lib/sidekiq/tasks/errors.rb
File without changes