deferrer 0.1.0 → 0.1.1

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: 47517fb6ffc62ca2b600c64f1a0a5ae5e2379239
4
- data.tar.gz: 06110ea8a1dbdf20002f5627798a33ac5fd550e8
3
+ metadata.gz: 455d09ae4793d235d895e80dff0d81f90bbef7ef
4
+ data.tar.gz: ba33ec69ad5f8d7144c3235585e436141e0fe21d
5
5
  SHA512:
6
- metadata.gz: 47f4549a640efb122f2726e3fdf052c7f9998f748d978f608cd440f74c8b5b352a157918423a5001d4f5688c617ca30a3fa89256c5d879e80e4cbece5cade884
7
- data.tar.gz: 1f330b0d1a8e6bae1a27dbb66fb0c69b5c0b83ca1818d4a3012ff2ef11738f34ff032753f55701d39548ce887cff9082a2f0a50cea7af87e620f0ed875f0ad3f
6
+ metadata.gz: a05628c41c9700e8330db18872f32c9d42c53843407aa8c8dd92997c67115b5e66766640992c20998e81ea3276cc9f189a47b04340eb1bd0f986f334b3187e69
7
+ data.tar.gz: 16906be529bd41cd0e5ec9304f5749a004f20d55fa5078a464a9bd91f9c382c5620a39a590077aed05ff630dc2e951bd0d0117421456b09b6a4fa9b42b6fac8a
data/README.md CHANGED
@@ -68,7 +68,7 @@ Deferrer.defer_in(9, 'identifier', Worker, 'update 3')
68
68
  ```
69
69
 
70
70
 
71
- It will stack all defered executions per identifier until first timeout expires (5 seconds) and then it will only execute the last update for the expired identifier, calling the deferrer worker:
71
+ It will stack all defered executions per identifier until first timeout expires (5 seconds) and then it will only process the last update for the expired identifier, calling the deferrer worker:
72
72
 
73
73
  ```ruby
74
74
  Deferrer.worker.call('Worker', 'update 3')
@@ -77,12 +77,21 @@ Deferrer.worker.call('Worker', 'update 3')
77
77
 
78
78
  ## Testing
79
79
 
80
- For testing, two options of the `run` method are useful. `single_run` will run the loop only once and `ignore_time` will not wait for time period to expire but execute to job now.
80
+ For testing, there are two options: single run and inline mode:
81
+
82
+ If you need to test in integration that the last update is processed use:
81
83
 
82
84
  ```ruby
85
+ # single_run - run the loop only once
86
+ # ignore_time - process the job now, don't wait for time period to expire
83
87
  Deferrer.run(single_run: true, ignore_time: true)
84
88
  ```
85
89
 
90
+ Alternativelly, if you want to process all updates, just use inline mode:
91
+
92
+ ```ruby
93
+ Deferrer.inline = true
94
+ ```
86
95
 
87
96
  ## Contributing
88
97
 
@@ -4,6 +4,7 @@ module Deferrer
4
4
  attr_reader :redis
5
5
  attr_accessor :logger
6
6
  attr_accessor :worker
7
+ attr_accessor :inline
7
8
 
8
9
  # Deferrer.redis_config = { :host => "localhost", :port => 6379 }
9
10
  def redis_config=(config)
@@ -4,6 +4,7 @@ module Deferrer
4
4
  loop_frequency = options.fetch(:loop_frequency, 0.1)
5
5
  single_run = options.fetch(:single_run, false)
6
6
  @ignore_time = options.fetch(:ignore_time, false)
7
+ @inline = options.fetch(:inline, false)
7
8
 
8
9
  raise WorkerNotConfigured unless worker
9
10
 
@@ -24,21 +25,20 @@ module Deferrer
24
25
  end
25
26
  end
26
27
 
27
- def next_item
28
+ def next_item(key = next_key)
29
+ return nil unless key
30
+
28
31
  item = nil
29
32
  decoded_item = nil
30
- key = next_key
31
-
32
- if key
33
- item = redis.rpop(key)
34
- if item
35
- decoded_item = decode(item)
36
- decoded_item['key'] = key
37
- end
38
33
 
39
- remove(key)
34
+ item = redis.rpop(key)
35
+ if item
36
+ decoded_item = decode(item)
37
+ decoded_item['key'] = key
40
38
  end
41
39
 
40
+ remove(key)
41
+
42
42
  decoded_item
43
43
  end
44
44
 
@@ -52,6 +52,8 @@ module Deferrer
52
52
  item = { 'args' => args }
53
53
 
54
54
  push_item(key, item, timestamp)
55
+
56
+ process_item(next_item(key)) if @inline
55
57
  end
56
58
 
57
59
  private
@@ -1,3 +1,3 @@
1
1
  module Deferrer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -142,4 +142,13 @@ describe Deferrer::Runner do
142
142
  expect { Deferrer.run(single_run: true) }.to raise_error
143
143
  end
144
144
  end
145
+
146
+ describe ".inline" do
147
+ it "ignores time to wait and performs jobs" do
148
+ Deferrer.inline = true
149
+ expect(Deferrer.worker).to receive(:call).with('Worker', { "c" => "d"})
150
+
151
+ Deferrer.defer_in(100, identifier, 'Worker', { c: :d })
152
+ end
153
+ end
145
154
  end
@@ -15,6 +15,7 @@ RSpec.configure do |config|
15
15
  config.before :each do
16
16
  Deferrer.redis.flushdb
17
17
  Deferrer.logger = nil
18
+ Deferrer.inline = false
18
19
  Deferrer.worker = lambda { |klass, *args| }
19
20
  end
20
21
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deferrer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dalibor Nasevic