asynchronic 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/asynchronic.rb +0 -2
- data/lib/asynchronic/data_store/helper.rb +42 -0
- data/lib/asynchronic/data_store/in_memory.rb +18 -22
- data/lib/asynchronic/data_store/key.rb +19 -1
- data/lib/asynchronic/data_store/lazy_store.rb +17 -0
- data/lib/asynchronic/data_store/lazy_value.rb +34 -0
- data/lib/asynchronic/data_store/readonly_store.rb +17 -0
- data/lib/asynchronic/data_store/redis.rb +16 -27
- data/lib/asynchronic/data_store/scoped_store.rb +52 -0
- data/lib/asynchronic/environment.rb +7 -27
- data/lib/asynchronic/job.rb +15 -27
- data/lib/asynchronic/process.rb +105 -76
- data/lib/asynchronic/queue_engine/in_memory.rb +5 -1
- data/lib/asynchronic/queue_engine/ost.rb +5 -1
- data/lib/asynchronic/queue_engine/synchronic.rb +68 -0
- data/lib/asynchronic/transparent_proxy.rb +52 -0
- data/lib/asynchronic/version.rb +1 -1
- data/spec/data_store/data_store_examples.rb +48 -32
- data/spec/data_store/in_memory_spec.rb +5 -0
- data/spec/data_store/key_spec.rb +36 -12
- data/spec/data_store/lazy_value_examples.rb +38 -0
- data/spec/data_store/redis_spec.rb +17 -0
- data/spec/data_store/scoped_store_spec.rb +60 -0
- data/spec/expectations.rb +7 -7
- data/spec/facade_spec.rb +15 -13
- data/spec/jobs.rb +70 -49
- data/spec/minitest_helper.rb +11 -1
- data/spec/process/life_cycle_examples.rb +149 -135
- data/spec/queue_engine/synchronic_spec.rb +27 -0
- data/spec/transparent_proxy_spec.rb +36 -0
- data/spec/worker/worker_examples.rb +1 -1
- metadata +117 -79
- checksums.yaml +0 -7
- data/lib/asynchronic/data_store/lookup.rb +0 -27
- data/lib/asynchronic/hash.rb +0 -31
- data/lib/asynchronic/runtime.rb +0 -40
- data/spec/data_store/lookup_spec.rb +0 -92
data/spec/minitest_helper.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'coverage_helper'
|
2
|
+
require 'asynchronic'
|
2
3
|
require 'minitest/autorun'
|
3
4
|
require 'minitest/great_expectations'
|
4
5
|
require 'turn'
|
5
|
-
require 'asynchronic'
|
6
6
|
require 'jobs'
|
7
7
|
require 'expectations'
|
8
8
|
|
9
9
|
Turn.config do |c|
|
10
10
|
c.format = :pretty
|
11
11
|
c.natural = true
|
12
|
+
c.ansi = true
|
12
13
|
end
|
13
14
|
|
14
15
|
class Module
|
@@ -26,4 +27,13 @@ class Minitest::Spec
|
|
26
27
|
Asynchronic::DataStore::Redis.new.clear
|
27
28
|
Asynchronic::QueueEngine::Ost.new.clear
|
28
29
|
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module Asynchronic::DataStore::Helper
|
33
|
+
def dump
|
34
|
+
puts 'DataStore:'
|
35
|
+
each do |k,v|
|
36
|
+
puts "#{k}: #{v}"
|
37
|
+
end
|
38
|
+
end
|
29
39
|
end
|
@@ -4,276 +4,290 @@ module LifeCycleExamples
|
|
4
4
|
|
5
5
|
let(:queue) { env.default_queue }
|
6
6
|
|
7
|
-
def
|
8
|
-
env.
|
7
|
+
def create(type, params={})
|
8
|
+
env.create_process type, params
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def execute(queue)
|
12
|
+
env.load_process(queue.pop).execute
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'Basic' do
|
16
|
-
process =
|
16
|
+
process = create BasicJob, input: 1
|
17
17
|
|
18
18
|
process.must_be_initialized
|
19
|
+
process.must_have_params input: 1
|
19
20
|
queue.must_be_empty
|
20
21
|
|
21
|
-
enqueue
|
22
|
+
process.enqueue
|
22
23
|
|
23
24
|
process.must_be_queued
|
24
|
-
process.must_have input: 1
|
25
25
|
queue.must_enqueued process
|
26
26
|
|
27
|
-
|
27
|
+
execute queue
|
28
28
|
|
29
29
|
process.must_be_completed
|
30
|
-
process.
|
30
|
+
process.result.must_equal 2
|
31
31
|
queue.must_be_empty
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'Sequential' do
|
35
|
-
process =
|
35
|
+
process = create SequentialJob, input: 50
|
36
36
|
|
37
37
|
process.must_be_initialized
|
38
|
+
process.must_have_params input: 50
|
38
39
|
queue.must_be_empty
|
39
40
|
|
40
|
-
enqueue
|
41
|
+
process.enqueue
|
41
42
|
|
42
43
|
process.must_be_queued
|
43
|
-
process.processes.must_be_empty
|
44
|
-
process.must_have input: 50
|
45
44
|
queue.must_enqueued process
|
46
45
|
|
47
|
-
|
46
|
+
execute queue
|
48
47
|
|
49
48
|
process.must_be_waiting
|
50
|
-
process
|
51
|
-
process
|
52
|
-
process.
|
53
|
-
|
49
|
+
process[SequentialJob::Step1].must_be_queued
|
50
|
+
process[SequentialJob::Step1].must_have_params input: 50
|
51
|
+
process[SequentialJob::Step2].must_be_pending
|
52
|
+
process[SequentialJob::Step2].must_have_params input: 50
|
53
|
+
queue.must_enqueued process[SequentialJob::Step1]
|
54
54
|
|
55
|
-
|
55
|
+
execute queue
|
56
56
|
|
57
57
|
process.must_be_waiting
|
58
|
-
process
|
59
|
-
process
|
60
|
-
process.
|
61
|
-
queue.must_enqueued process
|
58
|
+
process[SequentialJob::Step1].must_be_completed
|
59
|
+
process[SequentialJob::Step1].result.must_equal 500
|
60
|
+
process[SequentialJob::Step2].must_be_queued
|
61
|
+
queue.must_enqueued process[SequentialJob::Step2]
|
62
62
|
|
63
|
-
|
63
|
+
execute queue
|
64
64
|
|
65
65
|
process.must_be_completed
|
66
|
-
process.
|
67
|
-
process
|
68
|
-
process.
|
66
|
+
process.result.must_be_nil
|
67
|
+
process[SequentialJob::Step2].must_be_completed
|
68
|
+
process[SequentialJob::Step2].result.must_equal 5
|
69
69
|
queue.must_be_empty
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'Graph' do
|
73
|
-
process =
|
73
|
+
process = create GraphJob, input: 100
|
74
74
|
|
75
75
|
process.must_be_initialized
|
76
|
+
process.must_have_params input: 100
|
76
77
|
queue.must_be_empty
|
77
78
|
|
78
|
-
enqueue
|
79
|
+
process.enqueue
|
79
80
|
|
80
81
|
process.must_be_queued
|
81
|
-
process.processes.must_be_empty
|
82
|
-
process.must_have input: 100
|
83
82
|
queue.must_enqueued process
|
84
83
|
|
85
|
-
|
84
|
+
execute queue
|
86
85
|
|
87
86
|
process.must_be_waiting
|
88
|
-
process
|
89
|
-
process
|
90
|
-
process
|
91
|
-
process
|
92
|
-
process.
|
93
|
-
|
87
|
+
process[GraphJob::Sum].must_be_queued
|
88
|
+
process[GraphJob::Sum].must_have_params input: 100
|
89
|
+
process[GraphJob::TenPercent].must_be_pending
|
90
|
+
process[GraphJob::TenPercent].must_have_params input: nil
|
91
|
+
process[GraphJob::TwentyPercent].must_be_pending
|
92
|
+
process[GraphJob::TwentyPercent].must_have_params input: nil
|
93
|
+
process[GraphJob::Total].must_be_pending
|
94
|
+
process[GraphJob::Total].must_have_params '10%' => nil, '20%' => nil
|
95
|
+
queue.must_enqueued process[GraphJob::Sum]
|
94
96
|
|
95
|
-
|
97
|
+
execute queue
|
96
98
|
|
97
99
|
process.must_be_waiting
|
98
|
-
process
|
99
|
-
process
|
100
|
-
process
|
101
|
-
process
|
102
|
-
process.
|
103
|
-
|
100
|
+
process[GraphJob::Sum].must_be_completed
|
101
|
+
process[GraphJob::Sum].result.must_equal 200
|
102
|
+
process[GraphJob::TenPercent].must_be_queued
|
103
|
+
process[GraphJob::TenPercent].must_have_params input: 200
|
104
|
+
process[GraphJob::TwentyPercent].must_be_queued
|
105
|
+
process[GraphJob::TwentyPercent].must_have_params input: 200
|
106
|
+
process[GraphJob::Total].must_be_pending
|
107
|
+
queue.must_enqueued [process[GraphJob::TenPercent], process[GraphJob::TwentyPercent]]
|
104
108
|
|
105
|
-
2.times {
|
109
|
+
2.times { execute queue }
|
106
110
|
|
107
111
|
process.must_be_waiting
|
108
|
-
process
|
109
|
-
process
|
110
|
-
process
|
111
|
-
process
|
112
|
-
process.
|
113
|
-
queue.must_enqueued process
|
112
|
+
process[GraphJob::TenPercent].must_be_completed
|
113
|
+
process[GraphJob::TenPercent].result.must_equal 20
|
114
|
+
process[GraphJob::TwentyPercent].must_be_completed
|
115
|
+
process[GraphJob::TwentyPercent].result.must_equal 40
|
116
|
+
process[GraphJob::Total].must_be_queued
|
117
|
+
queue.must_enqueued process[GraphJob::Total]
|
114
118
|
|
115
|
-
|
119
|
+
execute queue
|
116
120
|
|
117
121
|
process.must_be_completed
|
118
|
-
process.
|
119
|
-
process
|
120
|
-
process
|
121
|
-
process.processes(GraphJob::Total).must_be_completed
|
122
|
-
process.must_have input: 100, sum: 200, '10%' => 20, '20%' => 40, output: {'10%' => 20, '20%' => 40}
|
122
|
+
process.result.must_equal '10%' => 20, '20%' => 40
|
123
|
+
process[GraphJob::Total].must_be_completed
|
124
|
+
process[GraphJob::Total].result.must_equal '10%' => 20, '20%' => 40
|
123
125
|
queue.must_be_empty
|
124
126
|
end
|
125
127
|
|
126
128
|
it 'Parallel' do
|
127
|
-
process =
|
129
|
+
process = create ParallelJob, input: 10, times: 3
|
128
130
|
|
129
131
|
process.must_be_initialized
|
132
|
+
process.must_have_params input: 10, times: 3
|
130
133
|
queue.must_be_empty
|
131
134
|
|
132
|
-
enqueue
|
135
|
+
process.enqueue
|
133
136
|
|
134
137
|
process.must_be_queued
|
135
138
|
process.processes.must_be_empty
|
136
|
-
process.must_have input: 10, times: 3
|
137
139
|
queue.must_enqueued process
|
138
140
|
|
139
|
-
|
141
|
+
execute queue
|
140
142
|
|
141
143
|
process.must_be_waiting
|
142
|
-
process.processes.
|
143
|
-
process.
|
144
|
+
process.processes.count.must_equal 3
|
145
|
+
process.processes.each_with_index do |p,i|
|
146
|
+
p.must_be_queued
|
147
|
+
p.must_have_params input: 10, index: i
|
148
|
+
end
|
144
149
|
queue.must_enqueued process.processes
|
145
150
|
|
146
|
-
3.times {
|
151
|
+
3.times { execute queue }
|
147
152
|
|
148
153
|
process.must_be_completed
|
149
|
-
process.
|
150
|
-
|
151
|
-
|
154
|
+
process.result.must_equal 3
|
155
|
+
process.processes.each_with_index do |p,i|
|
156
|
+
p.must_be_completed
|
157
|
+
p.result.must_equal 10 * i
|
158
|
+
end
|
152
159
|
queue.must_be_empty
|
153
160
|
end
|
154
161
|
|
155
162
|
it 'Nested' do
|
156
|
-
process =
|
163
|
+
process = create NestedJob, input: 4
|
157
164
|
|
158
165
|
process.must_be_initialized
|
166
|
+
process.must_have_params input: 4
|
159
167
|
queue.must_be_empty
|
160
168
|
|
161
|
-
enqueue
|
169
|
+
process.enqueue
|
162
170
|
|
163
171
|
process.must_be_queued
|
164
172
|
process.processes.must_be_empty
|
165
|
-
process.must_have input: 4
|
166
173
|
queue.must_enqueued process
|
167
174
|
|
168
|
-
|
175
|
+
execute queue
|
169
176
|
|
170
177
|
process.must_be_waiting
|
171
|
-
process
|
172
|
-
process
|
173
|
-
process.
|
174
|
-
queue.must_enqueued process
|
178
|
+
process[NestedJob::Level1].must_be_queued
|
179
|
+
process[NestedJob::Level1].must_have_params input: 4
|
180
|
+
process[NestedJob::Level1].processes.must_be_empty
|
181
|
+
queue.must_enqueued process[NestedJob::Level1]
|
175
182
|
|
176
|
-
|
183
|
+
execute queue
|
177
184
|
|
178
185
|
process.must_be_waiting
|
179
|
-
process
|
180
|
-
process
|
181
|
-
process.
|
182
|
-
queue.must_enqueued process
|
186
|
+
process[NestedJob::Level1].must_be_waiting
|
187
|
+
process[NestedJob::Level1][NestedJob::Level1::Level2].must_be_queued
|
188
|
+
process[NestedJob::Level1][NestedJob::Level1::Level2].must_have_params input: 5
|
189
|
+
queue.must_enqueued process[NestedJob::Level1][NestedJob::Level1::Level2]
|
183
190
|
|
184
|
-
|
191
|
+
execute queue
|
185
192
|
|
186
193
|
process.must_be_completed
|
187
|
-
process.
|
188
|
-
process
|
189
|
-
process.
|
194
|
+
process.result.must_equal 25
|
195
|
+
process[NestedJob::Level1].must_be_completed
|
196
|
+
process[NestedJob::Level1].result.must_equal 25
|
197
|
+
process[NestedJob::Level1][NestedJob::Level1::Level2].must_be_completed
|
198
|
+
process[NestedJob::Level1][NestedJob::Level1::Level2].result.must_equal 25
|
190
199
|
queue.must_be_empty
|
191
200
|
end
|
192
201
|
|
193
|
-
it '
|
194
|
-
process =
|
202
|
+
it 'Alias' do
|
203
|
+
process = create AliasJob
|
195
204
|
|
196
205
|
process.must_be_initialized
|
197
206
|
queue.must_be_empty
|
198
207
|
|
199
|
-
enqueue
|
208
|
+
process.enqueue
|
200
209
|
|
201
210
|
process.must_be_queued
|
202
211
|
process.processes.must_be_empty
|
203
|
-
process.data.must_be_empty
|
204
212
|
queue.must_enqueued process
|
205
213
|
|
206
|
-
|
214
|
+
execute queue
|
207
215
|
|
208
216
|
process.must_be_waiting
|
209
|
-
process
|
210
|
-
process.
|
211
|
-
process
|
212
|
-
process.
|
213
|
-
|
217
|
+
process[:word_1].must_be_queued
|
218
|
+
process[:word_1].must_have_params text: 'Take'
|
219
|
+
process[:word_2].must_be_pending
|
220
|
+
process[:word_2].must_have_params text: 'it', prefix: nil
|
221
|
+
process[:word_3].must_be_pending
|
222
|
+
process[:word_3].must_have_params text: 'easy', prefix: nil
|
223
|
+
queue.must_enqueued process[:word_1]
|
214
224
|
|
215
|
-
|
225
|
+
execute queue
|
216
226
|
|
217
227
|
process.must_be_waiting
|
218
|
-
process
|
219
|
-
process
|
220
|
-
process
|
221
|
-
process.
|
222
|
-
|
228
|
+
process[:word_1].must_be_completed
|
229
|
+
process[:word_1].result.must_equal 'Take'
|
230
|
+
process[:word_2].must_be_queued
|
231
|
+
process[:word_2].must_have_params text: 'it', prefix: 'Take'
|
232
|
+
process[:word_3].must_be_pending
|
233
|
+
queue.must_enqueued process[:word_2]
|
223
234
|
|
224
|
-
|
235
|
+
execute queue
|
225
236
|
|
226
237
|
process.must_be_waiting
|
227
|
-
process
|
228
|
-
process
|
229
|
-
process
|
230
|
-
process.
|
231
|
-
|
238
|
+
process[:word_1].must_be_completed
|
239
|
+
process[:word_2].must_be_completed
|
240
|
+
process[:word_2].result.must_equal 'Take it'
|
241
|
+
process[:word_3].must_be_queued
|
242
|
+
process[:word_3].must_have_params text: 'easy', prefix: 'Take it'
|
243
|
+
queue.must_enqueued process[:word_3]
|
232
244
|
|
233
|
-
|
245
|
+
execute queue
|
234
246
|
|
235
247
|
process.must_be_completed
|
236
|
-
process.
|
237
|
-
process
|
238
|
-
process
|
239
|
-
process.
|
248
|
+
process.result.must_equal 'Take it easy'
|
249
|
+
process[:word_1].must_be_completed
|
250
|
+
process[:word_2].must_be_completed
|
251
|
+
process[:word_3].must_be_completed
|
252
|
+
process[:word_3].result.must_equal 'Take it easy'
|
240
253
|
queue.must_be_empty
|
241
254
|
end
|
242
255
|
|
243
256
|
it 'Custom queue' do
|
244
|
-
process =
|
257
|
+
process = create CustomQueueJob, input: 'hello'
|
245
258
|
|
246
259
|
process.must_be_initialized
|
247
|
-
|
260
|
+
process.must_have_params input: 'hello'
|
261
|
+
|
248
262
|
env.queue(:queue_1).must_be_empty
|
249
263
|
env.queue(:queue_2).must_be_empty
|
250
264
|
env.queue(:queue_3).must_be_empty
|
251
265
|
|
252
|
-
enqueue
|
266
|
+
process.enqueue
|
253
267
|
|
254
268
|
process.must_be_queued
|
255
269
|
process.processes.must_be_empty
|
256
|
-
process.must_have input: 'hello'
|
257
270
|
|
258
271
|
env.queue(:queue_1).must_enqueued process
|
259
272
|
env.queue(:queue_2).must_be_empty
|
260
273
|
env.queue(:queue_3).must_be_empty
|
261
274
|
|
262
|
-
|
275
|
+
execute env.queue(:queue_1)
|
263
276
|
|
264
277
|
process.must_be_waiting
|
265
|
-
process
|
266
|
-
process.
|
278
|
+
process[CustomQueueJob::Reverse].must_be_queued
|
279
|
+
process[CustomQueueJob::Reverse].must_have_params input: 'hello'
|
267
280
|
|
268
281
|
env.queue(:queue_1).must_be_empty
|
269
|
-
env.queue(:queue_2).must_enqueued process
|
282
|
+
env.queue(:queue_2).must_enqueued process[CustomQueueJob::Reverse]
|
270
283
|
env.queue(:queue_3).must_be_empty
|
271
284
|
|
272
|
-
|
285
|
+
execute env.queue(:queue_2)
|
273
286
|
|
274
287
|
process.must_be_completed
|
275
|
-
process.
|
276
|
-
process.
|
288
|
+
process.result.must_equal 'olleh'
|
289
|
+
process[CustomQueueJob::Reverse].must_be_completed
|
290
|
+
process[CustomQueueJob::Reverse].result.must_equal 'olleh'
|
277
291
|
|
278
292
|
env.queue(:queue_1).must_be_empty
|
279
293
|
env.queue(:queue_2).must_be_empty
|
@@ -281,17 +295,17 @@ module LifeCycleExamples
|
|
281
295
|
end
|
282
296
|
|
283
297
|
it 'Exception' do
|
284
|
-
process =
|
298
|
+
process = create ExceptionJob
|
285
299
|
|
286
300
|
process.must_be_initialized
|
287
301
|
queue.must_be_empty
|
288
302
|
|
289
|
-
enqueue
|
303
|
+
process.enqueue
|
290
304
|
|
291
305
|
process.must_be_queued
|
292
306
|
queue.must_enqueued process
|
293
307
|
|
294
|
-
|
308
|
+
execute queue
|
295
309
|
|
296
310
|
process.must_be_aborted
|
297
311
|
process.error.must_be_instance_of Asynchronic::Error
|
@@ -299,31 +313,31 @@ module LifeCycleExamples
|
|
299
313
|
end
|
300
314
|
|
301
315
|
it 'Inner exception' do
|
302
|
-
process =
|
316
|
+
process = create InnerExceptionJob
|
303
317
|
|
304
318
|
process.must_be_initialized
|
305
319
|
queue.must_be_empty
|
306
320
|
|
307
|
-
enqueue
|
321
|
+
process.enqueue
|
308
322
|
|
309
323
|
process.must_be_queued
|
310
324
|
queue.must_enqueued process
|
311
325
|
|
312
|
-
|
326
|
+
execute queue
|
313
327
|
|
314
328
|
process.must_be_waiting
|
315
|
-
process
|
316
|
-
queue.must_enqueued process
|
329
|
+
process[ExceptionJob].must_be_queued
|
330
|
+
queue.must_enqueued process[ExceptionJob]
|
317
331
|
|
318
|
-
|
332
|
+
execute queue
|
319
333
|
|
320
334
|
process.must_be_aborted
|
321
335
|
process.error.must_be_instance_of Asynchronic::Error
|
322
336
|
process.error.message.must_equal 'Error caused by ExceptionJob'
|
323
337
|
|
324
|
-
process
|
325
|
-
process
|
326
|
-
process
|
338
|
+
process[ExceptionJob].must_be_aborted
|
339
|
+
process[ExceptionJob].error.must_be_instance_of Asynchronic::Error
|
340
|
+
process[ExceptionJob].error.message.must_equal 'Error for test'
|
327
341
|
end
|
328
342
|
|
329
343
|
end
|