sidekiq-recursive 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +24 -0
- data/lib/sidekiq/recursive.rb +3 -0
- data/lib/sidekiq/recursive/hooks.rb +2 -0
- data/lib/sidekiq/recursive/hooks/after_all.rb +9 -0
- data/lib/sidekiq/recursive/hooks/before_all.rb +8 -0
- data/lib/sidekiq/recursive/perform.rb +1 -1
- data/lib/sidekiq/recursive/start.rb +1 -0
- data/lib/sidekiq/recursive/version.rb +1 -1
- data/lib/sidekiq/recursive/worker.rb +8 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c314d036966c7977f1647dca8d10a139d2897a26
|
4
|
+
data.tar.gz: 87d913ed242b44275d845bf811521a71163854f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e0876def8a48e6cae0bf6201f616eb4a6d69a8a90ebbb47d8ef0188d43942ee9374a197c4e06c93e73ff98cdd4f56a8d98ee278949b6a0152f3aa1db327c485
|
7
|
+
data.tar.gz: 42305c2399da0bcd64de5766160a15a79967c2e5421218d28aa57f5b2369e8d4b15c69be51907d6b3e24126f954b46d8b57dc6cead6ae8de6b018c65c37c7334
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -35,6 +35,30 @@ user_ids = User.where(is_old: true).ids
|
|
35
35
|
CleanUpOldUsers.run(user_ids)
|
36
36
|
```
|
37
37
|
|
38
|
+
#### before_all and after_all hooks
|
39
|
+
```ruby
|
40
|
+
class CleanUpOldUsers
|
41
|
+
include Sidekiq::Worker
|
42
|
+
include Sidekiq::Recursive::Worker
|
43
|
+
|
44
|
+
recursive_worker_count 5
|
45
|
+
before_all :bar
|
46
|
+
after_all :foo
|
47
|
+
|
48
|
+
def bar
|
49
|
+
# do something before starting all workers
|
50
|
+
end
|
51
|
+
|
52
|
+
def process(user_id)
|
53
|
+
User.destroy(user_id)
|
54
|
+
end
|
55
|
+
|
56
|
+
def foo
|
57
|
+
# do something after all workers are finished
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
38
62
|
## Development
|
39
63
|
|
40
64
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/sidekiq/recursive.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require 'sidekiq/recursive/argument_queue'
|
2
|
+
require 'sidekiq/recursive/hooks'
|
3
|
+
require 'sidekiq/recursive/hooks/after_all'
|
4
|
+
require 'sidekiq/recursive/hooks/before_all'
|
2
5
|
require 'sidekiq/recursive/perform'
|
3
6
|
require 'sidekiq/recursive/start'
|
4
7
|
require 'sidekiq/recursive/version'
|
@@ -4,7 +4,7 @@ class Sidekiq::Recursive::Perform
|
|
4
4
|
return worker_instance.process(argument) if worker_id == :failed_worker
|
5
5
|
safe_process(worker_instance, argument)
|
6
6
|
next_argument = Sidekiq::Recursive::ArgumentQueue.pop(worker)
|
7
|
-
return unless next_argument
|
7
|
+
return Sidekiq::Recursive::Hooks::AfterAll.run(worker, worker_id) unless next_argument
|
8
8
|
worker.perform_async(worker_id, next_argument)
|
9
9
|
|
10
10
|
true
|
@@ -1,6 +1,7 @@
|
|
1
1
|
class Sidekiq::Recursive::Start
|
2
2
|
def self.run(worker, arguments)
|
3
3
|
Sidekiq::Recursive::ArgumentQueue.push(worker, arguments)
|
4
|
+
Sidekiq::Recursive::Hooks::BeforeAll.run(worker)
|
4
5
|
|
5
6
|
1.upto(worker.recursive_worker_count) do |worker_id|
|
6
7
|
argument = Sidekiq::Recursive::ArgumentQueue.pop(worker)
|
@@ -14,6 +14,14 @@ module Sidekiq::Recursive::Worker
|
|
14
14
|
raise Sidekiq::Recursive::UndefinedWorkerCountError if count.nil? && @worker_count.nil?
|
15
15
|
@worker_count ||= count
|
16
16
|
end
|
17
|
+
|
18
|
+
def before_all(action_name = nil)
|
19
|
+
@before_all ||= action_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def after_all(action_name = nil)
|
23
|
+
@after_all ||= action_name
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
27
|
module InstanceMethods
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Kazakauskas
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|
@@ -120,6 +120,9 @@ files:
|
|
120
120
|
- bin/setup
|
121
121
|
- lib/sidekiq/recursive.rb
|
122
122
|
- lib/sidekiq/recursive/argument_queue.rb
|
123
|
+
- lib/sidekiq/recursive/hooks.rb
|
124
|
+
- lib/sidekiq/recursive/hooks/after_all.rb
|
125
|
+
- lib/sidekiq/recursive/hooks/before_all.rb
|
123
126
|
- lib/sidekiq/recursive/perform.rb
|
124
127
|
- lib/sidekiq/recursive/start.rb
|
125
128
|
- lib/sidekiq/recursive/version.rb
|