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 +4 -4
- data/README.md +11 -2
- data/lib/deferrer/configuration.rb +1 -0
- data/lib/deferrer/runner.rb +12 -10
- data/lib/deferrer/version.rb +1 -1
- data/spec/deferrer/runner_spec.rb +9 -0
- data/spec/spec_helper.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 455d09ae4793d235d895e80dff0d81f90bbef7ef
|
4
|
+
data.tar.gz: ba33ec69ad5f8d7144c3235585e436141e0fe21d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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,
|
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
|
|
data/lib/deferrer/runner.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/deferrer/version.rb
CHANGED
@@ -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
|
data/spec/spec_helper.rb
CHANGED