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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f8039623c6e6890c840050a797e2d2a4a336d0e
4
- data.tar.gz: a34b1e3f4f7385f3286e0e6dffc997f54e6cd94e
3
+ metadata.gz: c314d036966c7977f1647dca8d10a139d2897a26
4
+ data.tar.gz: 87d913ed242b44275d845bf811521a71163854f6
5
5
  SHA512:
6
- metadata.gz: 7d1b745ac1162cb03dc27c89d2e9e87674ff395b235d22ff75d3795d6da994470f4bf603cb3ff019fc684df1858b2a0d875bb45c3604be1c583e8ebd3f18bf18
7
- data.tar.gz: 25f1d7fe4856aa606bb73935b3ae3580ff10e354bf6d12a1f096e2ba8bfb4af0bdccb85e923912528318a188737da6884913498fa78c3b47a70c42810a8e5386
6
+ metadata.gz: 3e0876def8a48e6cae0bf6201f616eb4a6d69a8a90ebbb47d8ef0188d43942ee9374a197c4e06c93e73ff98cdd4f56a8d98ee278949b6a0152f3aa1db327c485
7
+ data.tar.gz: 42305c2399da0bcd64de5766160a15a79967c2e5421218d28aa57f5b2369e8d4b15c69be51907d6b3e24126f954b46d8b57dc6cead6ae8de6b018c65c37c7334
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sidekiq-recursive (0.1.0)
4
+ sidekiq-recursive (0.2.0)
5
5
  sidekiq (~> 5.1, >= 3.0)
6
6
 
7
7
  GEM
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.
@@ -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'
@@ -0,0 +1,2 @@
1
+ module Sidekiq::Recursive::Hooks
2
+ end
@@ -0,0 +1,9 @@
1
+ class Sidekiq::Recursive::Hooks::AfterAll
2
+ def self.run(worker, worker_id)
3
+ action_name = worker.after_all
4
+ return unless action_name
5
+ return unless worker.recursive_worker_count == worker_id
6
+ worker.new.send(action_name)
7
+ true
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class Sidekiq::Recursive::Hooks::BeforeAll
2
+ def self.run(worker)
3
+ action_name = worker.before_all
4
+ return unless action_name
5
+ worker.new.send(action_name)
6
+ true
7
+ end
8
+ end
@@ -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)
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Recursive
3
- VERSION = "0.1.0"
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -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.1.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-03-31 00:00:00.000000000 Z
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