sidekiq-tasks 0.1.2 → 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 +4 -4
- data/.rubocop.yml +2 -2
- data/CHANGELOG.md +12 -0
- data/README.md +28 -2
- data/lib/sidekiq/tasks/set.rb +6 -1
- data/lib/sidekiq/tasks/strategies/rules/disable_with_comment.rb +19 -0
- data/lib/sidekiq/tasks/strategies/rules/enable_with_comment.rb +41 -10
- data/lib/sidekiq/tasks/strategies/rules.rb +1 -0
- data/lib/sidekiq/tasks/version.rb +1 -1
- data/lib/sidekiq/tasks/web/extension.rb +3 -3
- data/lib/sidekiq/tasks/web/helpers/application_helper.rb +12 -0
- data/lib/sidekiq/tasks/web.rb +1 -0
- metadata +5 -4
- /data/lib/{sidekiq/sidekiq-tasks.rb → sidekiq-tasks.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f8d4001fa7c85be52975408343d261f87b68da263508e6a97e23d2327685121
|
4
|
+
data.tar.gz: a0e978fd7ea7a0959571d9c635cbecf667d319f14e3424cbd68bf90f4f936db6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83bfda60244fda1c62876d2ea6f8a0d61f32e558c0492fd28ac4936d32fc601969c5b676ac18b21d9533796b4e21de9f57ff509b65acb253d0b5d635f52b2249
|
7
|
+
data.tar.gz: 15ec2cf69ea14409f2c852c3fc3c82ffb49dabaedaccccf93084b86d88099d328f6a2b8f03e57578acff9a2272d2782a4653dc42d46c8f76625ad287bf5ab0fb
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 3.
|
2
|
+
TargetRubyVersion: 3.0
|
3
3
|
NewCops: disable
|
4
4
|
SuggestExtensions: false
|
5
5
|
|
@@ -33,7 +33,7 @@ Metrics/PerceivedComplexity:
|
|
33
33
|
|
34
34
|
Naming/FileName:
|
35
35
|
Exclude:
|
36
|
-
- lib/sidekiq
|
36
|
+
- lib/sidekiq-tasks.rb
|
37
37
|
|
38
38
|
Naming/MemoizedInstanceVariableName:
|
39
39
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
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
|
+
|
10
|
+
### [0.1.3] - 2025-03-22
|
11
|
+
|
12
|
+
- Change required Ruby version to 3.0.0.
|
13
|
+
- Add `DisableWithComment` rule to disable a specific task with a magic comment.
|
14
|
+
|
3
15
|
### [0.1.2] - 2025-03-22
|
4
16
|
|
5
17
|
- Update plugin registration for Sidekiq 7.3+ compatibility.
|
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
|
50
|
+
Example of an enabled task in `lib/tasks/my_task.rake`:
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
# sidekiq-tasks:enable
|
@@ -56,10 +56,35 @@ task :my_task do
|
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
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))
|
75
|
+
It works similarly to `EnableWithComment`, but with inverted logic. Example of a disabled task:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# sidekiq-tasks:disable
|
79
|
+
task :my_task do
|
80
|
+
puts "my_task"
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
59
84
|
## Strategies configuration
|
60
85
|
|
61
86
|
Strategies can be configured through the `config.strategies` option.
|
62
|
-
For example if you want to
|
87
|
+
For example if you want to enable all tasks in the lib folder and disable a few specific ones manually:
|
63
88
|
|
64
89
|
```ruby
|
65
90
|
Sidekiq::Tasks.configure do |config|
|
@@ -67,6 +92,7 @@ Sidekiq::Tasks.configure do |config|
|
|
67
92
|
Sidekiq::Tasks::Strategies::RakeTask.new(
|
68
93
|
rules: [
|
69
94
|
Sidekiq::Tasks::Strategies::Rules::TaskFromLib.new,
|
95
|
+
Sidekiq::Tasks::Strategies::Rules::DisableWithComment.new,
|
70
96
|
]
|
71
97
|
)
|
72
98
|
]
|
data/lib/sidekiq/tasks/set.rb
CHANGED
@@ -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)
|
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
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Sidekiq
|
2
|
+
module Tasks
|
3
|
+
module Strategies
|
4
|
+
module Rules
|
5
|
+
class DisableWithComment < EnableWithComment
|
6
|
+
def respected?(task)
|
7
|
+
!super
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def magic_comment_regex
|
13
|
+
/sidekiq-tasks:disable/
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -3,24 +3,55 @@ module Sidekiq
|
|
3
3
|
module Strategies
|
4
4
|
module Rules
|
5
5
|
class EnableWithComment < Base
|
6
|
-
MAGIC_COMMENT_REGEX = /sidekiq-tasks:enable/
|
7
|
-
|
8
6
|
def respected?(task)
|
9
|
-
file,
|
10
|
-
|
11
|
-
|
7
|
+
file, line_number = task.locations.first.split(":")
|
8
|
+
line_number = line_number.to_i
|
9
|
+
|
10
|
+
lines = read_file_lines(file)
|
11
|
+
|
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
|
12
18
|
|
13
|
-
|
19
|
+
namespace_has_magic_comment?(lines, namespace_line_index)
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def magic_comment_regex
|
25
|
+
/sidekiq-tasks:enable/
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def read_file_lines(file)
|
31
|
+
File.read(file).split("\n")
|
14
32
|
rescue Errno::ENOENT
|
15
33
|
raise ArgumentError, "File '#{file}' not found"
|
16
34
|
end
|
17
35
|
|
18
|
-
|
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
|
19
47
|
|
20
|
-
def
|
21
|
-
|
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
|
22
52
|
|
23
|
-
|
53
|
+
def namespace_name(task)
|
54
|
+
task.name.split(":").first
|
24
55
|
end
|
25
56
|
end
|
26
57
|
end
|
@@ -5,6 +5,7 @@ module Sidekiq
|
|
5
5
|
autoload :Base, "sidekiq/tasks/strategies/rules/base"
|
6
6
|
autoload :TaskFromLib, "sidekiq/tasks/strategies/rules/task_from_lib"
|
7
7
|
autoload :EnableWithComment, "sidekiq/tasks/strategies/rules/enable_with_comment"
|
8
|
+
autoload :DisableWithComment, "sidekiq/tasks/strategies/rules/disable_with_comment"
|
8
9
|
end
|
9
10
|
end
|
10
11
|
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(
|
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
|
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,
|
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
|
data/lib/sidekiq/tasks/web.rb
CHANGED
@@ -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.
|
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-
|
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
|
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
|
@@ -250,6 +250,7 @@ files:
|
|
250
250
|
- lib/sidekiq/tasks/strategies/rake_task.rb
|
251
251
|
- lib/sidekiq/tasks/strategies/rules.rb
|
252
252
|
- lib/sidekiq/tasks/strategies/rules/base.rb
|
253
|
+
- lib/sidekiq/tasks/strategies/rules/disable_with_comment.rb
|
253
254
|
- lib/sidekiq/tasks/strategies/rules/enable_with_comment.rb
|
254
255
|
- lib/sidekiq/tasks/strategies/rules/task_from_lib.rb
|
255
256
|
- lib/sidekiq/tasks/task.rb
|
@@ -293,7 +294,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
293
294
|
requirements:
|
294
295
|
- - ">="
|
295
296
|
- !ruby/object:Gem::Version
|
296
|
-
version: 3.
|
297
|
+
version: '3.0'
|
297
298
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
298
299
|
requirements:
|
299
300
|
- - ">="
|
File without changes
|