sidekiq-recursive 0.2.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sidekiq/recursive/argument_queue.rb +6 -6
- data/lib/sidekiq/recursive/hooks/after_all.rb +5 -4
- data/lib/sidekiq/recursive/hooks/before_all.rb +5 -3
- data/lib/sidekiq/recursive/perform.rb +8 -6
- data/lib/sidekiq/recursive/start.rb +6 -6
- data/lib/sidekiq/recursive/worker.rb +9 -4
- data/lib/sidekiq/recursive.rb +7 -8
- metadata +6 -8
- data/lib/sidekiq/recursive/hooks.rb +0 -2
- data/lib/sidekiq/recursive/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2598b52683b9b25a1d979f9f977d1cff3d7803383c1393eb65b03e9efd7d1c1
|
4
|
+
data.tar.gz: d2787b0dbf064b3b30848aa161ccd2d6c1fad2acaccd15c2adf2bfa8ef3acf91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71ec4f61aa6dec811ae07d6331b6b15a7d825de4c3b3c4182628d58a27bc062a26b4eb2a76358a42340b989013f1f82e7c0b4d2461a3daa68004f0024f94c851
|
7
|
+
data.tar.gz: 0fe43877b6c573015d36c227974b02babc7d451ca20de0b4b3d426807f46347ed0f16817c797cf5194aeb02e59e58aede15379a7472913eb64947e271e1d98db
|
@@ -1,21 +1,21 @@
|
|
1
1
|
class Sidekiq::Recursive::ArgumentQueue
|
2
2
|
class << self
|
3
|
-
def push(
|
4
|
-
arguments_queue_name = generate_arguments_queue_name(
|
3
|
+
def push(worker_class, arguments)
|
4
|
+
arguments_queue_name = generate_arguments_queue_name(worker_class)
|
5
5
|
redis_client.rpush(arguments_queue_name, arguments)
|
6
6
|
|
7
7
|
true
|
8
8
|
end
|
9
9
|
|
10
|
-
def pop(
|
11
|
-
arguments_queue_name = generate_arguments_queue_name(
|
10
|
+
def pop(worker_class)
|
11
|
+
arguments_queue_name = generate_arguments_queue_name(worker_class)
|
12
12
|
redis_client.lpop(arguments_queue_name)
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def generate_arguments_queue_name(
|
18
|
-
|
17
|
+
def generate_arguments_queue_name(worker_class)
|
18
|
+
"recursive_queue__#{worker_class}"
|
19
19
|
end
|
20
20
|
|
21
21
|
def redis_client
|
@@ -1,9 +1,10 @@
|
|
1
1
|
class Sidekiq::Recursive::Hooks::AfterAll
|
2
|
-
def self.run(
|
3
|
-
action_name =
|
2
|
+
def self.run(worker_class, worker_id)
|
3
|
+
action_name = worker_class.after_all
|
4
4
|
return unless action_name
|
5
|
-
return unless
|
6
|
-
|
5
|
+
return unless worker_class.worker_count == worker_id
|
6
|
+
|
7
|
+
worker_class.new.send(action_name)
|
7
8
|
true
|
8
9
|
end
|
9
10
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
class Sidekiq::Recursive::Hooks::BeforeAll
|
2
|
-
def self.run(
|
3
|
-
action_name =
|
2
|
+
def self.run(worker_class)
|
3
|
+
action_name = worker_class.before_all
|
4
4
|
return unless action_name
|
5
|
-
|
5
|
+
|
6
|
+
worker_class.new.send(action_name)
|
7
|
+
|
6
8
|
true
|
7
9
|
end
|
8
10
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
class Sidekiq::Recursive::Perform
|
2
2
|
def self.run(worker_instance, worker_id, argument)
|
3
|
-
|
4
|
-
return worker_instance.process(argument) if worker_id ==
|
3
|
+
worker_class = worker_instance.class
|
4
|
+
return worker_instance.process(argument) if worker_id == Sidekiq::Recursive::FAILED_WORKER_ID
|
5
|
+
|
5
6
|
safe_process(worker_instance, argument)
|
6
|
-
next_argument = Sidekiq::Recursive::ArgumentQueue.pop(
|
7
|
-
return Sidekiq::Recursive::Hooks::AfterAll.run(
|
8
|
-
|
7
|
+
next_argument = Sidekiq::Recursive::ArgumentQueue.pop(worker_class)
|
8
|
+
return Sidekiq::Recursive::Hooks::AfterAll.run(worker_class, worker_id) unless next_argument
|
9
|
+
|
10
|
+
worker_class.perform_async(worker_id, next_argument)
|
9
11
|
|
10
12
|
true
|
11
13
|
end
|
@@ -13,6 +15,6 @@ class Sidekiq::Recursive::Perform
|
|
13
15
|
def self.safe_process(worker_instance, argument)
|
14
16
|
worker_instance.process(argument)
|
15
17
|
rescue StandardError
|
16
|
-
worker_instance.class.perform_async(
|
18
|
+
worker_instance.class.perform_async(Sidekiq::Recursive::FAILED_WORKER_ID, argument)
|
17
19
|
end
|
18
20
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class Sidekiq::Recursive::Start
|
2
|
-
def self.run(
|
3
|
-
Sidekiq::Recursive::ArgumentQueue.push(
|
4
|
-
Sidekiq::Recursive::Hooks::BeforeAll.run(
|
2
|
+
def self.run(worker_class, arguments)
|
3
|
+
Sidekiq::Recursive::ArgumentQueue.push(worker_class, arguments)
|
4
|
+
Sidekiq::Recursive::Hooks::BeforeAll.run(worker_class)
|
5
5
|
|
6
|
-
1.upto(
|
7
|
-
argument = Sidekiq::Recursive::ArgumentQueue.pop(
|
8
|
-
|
6
|
+
1.upto(worker_class.worker_count) do |worker_id|
|
7
|
+
argument = Sidekiq::Recursive::ArgumentQueue.pop(worker_class)
|
8
|
+
worker_class.perform_async(worker_id, argument)
|
9
9
|
end
|
10
10
|
|
11
11
|
true
|
@@ -5,14 +5,18 @@ module Sidekiq::Recursive::Worker
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
-
def
|
8
|
+
def call(arguments)
|
9
9
|
Sidekiq::Recursive::Start.run(self, arguments)
|
10
|
+
|
10
11
|
true
|
11
12
|
end
|
12
13
|
|
13
|
-
def recursive_worker_count(
|
14
|
-
|
15
|
-
|
14
|
+
def recursive_worker_count(worker_count)
|
15
|
+
@worker_count = worker_count
|
16
|
+
end
|
17
|
+
|
18
|
+
def worker_count
|
19
|
+
@worker_count
|
16
20
|
end
|
17
21
|
|
18
22
|
def before_all(action_name = nil)
|
@@ -27,6 +31,7 @@ module Sidekiq::Recursive::Worker
|
|
27
31
|
module InstanceMethods
|
28
32
|
def perform(worker_id, argument)
|
29
33
|
Sidekiq::Recursive::Perform.run(self, worker_id, argument)
|
34
|
+
|
30
35
|
true
|
31
36
|
end
|
32
37
|
end
|
data/lib/sidekiq/recursive.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
|
1
|
+
module Sidekiq
|
2
|
+
module Recursive
|
3
|
+
FAILED_WORKER_ID = 'failed_worker'
|
4
|
+
|
5
|
+
module Hooks; end
|
6
|
+
end
|
7
|
+
end
|
2
8
|
|
3
9
|
require 'sidekiq/recursive/argument_queue'
|
4
|
-
require 'sidekiq/recursive/hooks'
|
5
10
|
require 'sidekiq/recursive/hooks/after_all'
|
6
11
|
require 'sidekiq/recursive/hooks/before_all'
|
7
12
|
require 'sidekiq/recursive/perform'
|
8
13
|
require 'sidekiq/recursive/start'
|
9
14
|
require 'sidekiq/recursive/worker'
|
10
|
-
|
11
|
-
module Sidekiq
|
12
|
-
module Recursive
|
13
|
-
class UndefinedWorkerCountError < StandardError; end
|
14
|
-
end
|
15
|
-
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidekiq-recursive
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Kazakauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-05-
|
11
|
+
date: 2024-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -17,9 +17,9 @@ dependencies:
|
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
-
- - "
|
20
|
+
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '8.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,9 +27,9 @@ dependencies:
|
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.0'
|
30
|
-
- - "
|
30
|
+
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '8.0'
|
33
33
|
description: Use simple recursion to limit sidekiq workers per job.
|
34
34
|
email: leakymirror@gmail.com
|
35
35
|
executables: []
|
@@ -38,12 +38,10 @@ extra_rdoc_files: []
|
|
38
38
|
files:
|
39
39
|
- lib/sidekiq/recursive.rb
|
40
40
|
- lib/sidekiq/recursive/argument_queue.rb
|
41
|
-
- lib/sidekiq/recursive/hooks.rb
|
42
41
|
- lib/sidekiq/recursive/hooks/after_all.rb
|
43
42
|
- lib/sidekiq/recursive/hooks/before_all.rb
|
44
43
|
- lib/sidekiq/recursive/perform.rb
|
45
44
|
- lib/sidekiq/recursive/start.rb
|
46
|
-
- lib/sidekiq/recursive/version.rb
|
47
45
|
- lib/sidekiq/recursive/worker.rb
|
48
46
|
homepage: https://github.com/justaskz/sidekiq-recursive
|
49
47
|
licenses:
|