asynchronic 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ee0dd3eef07147809867c45baccde4b008120a1
4
+ data.tar.gz: 74299af765d4d3e26a42add38cec3ef7bcb3fd0a
5
+ SHA512:
6
+ metadata.gz: d83f18a63b3ba1be37b25750498e0aa33f0c1490b28756472791bab825092d9de154d53c7c4cf6ea612d91ce2a2fe85901a94ef8c92cb03bcb9c93531af36dd1
7
+ data.tar.gz: 6ee3a6051385501266ae97b7c8a69fbbf31a9f45ccc26bd881cb7f273dab2141c4f5eb4631710017dd28345373feae823bfc98a5e2cce1ec57face5a995e9aae
data/asynchronic.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'redis', '~> 3.0'
22
22
  spec.add_dependency 'ost', '~> 0.1'
23
23
  spec.add_dependency 'class_config', '~> 0.0'
24
+ spec.add_dependency 'transparent_proxy', '~> 0.0'
24
25
 
25
26
  spec.add_development_dependency 'bundler', '~> 1.3'
26
27
  spec.add_development_dependency 'rake'
@@ -37,6 +37,10 @@ module Asynchronic
37
37
  LazyStore.new self
38
38
  end
39
39
 
40
+ def no_lazy
41
+ NoLazyStore.new self
42
+ end
43
+
40
44
  end
41
45
  end
42
46
  end
@@ -1,9 +1,9 @@
1
- require_relative '../transparent_proxy'
2
-
3
1
  module Asynchronic
4
2
  module DataStore
5
3
  class LazyStore < TransparentProxy
6
4
 
5
+ include Helper
6
+
7
7
  def [](key)
8
8
  LazyValue.new __getobj__, key
9
9
  end
@@ -1,5 +1,3 @@
1
- require_relative '../transparent_proxy'
2
-
3
1
  module Asynchronic
4
2
  module DataStore
5
3
  class LazyValue < TransparentProxy
@@ -23,6 +21,10 @@ module Asynchronic
23
21
  @data_store_class.connect @data_store_connection
24
22
  end
25
23
 
24
+ def to_value
25
+ __getobj__
26
+ end
27
+
26
28
  private
27
29
 
28
30
  def __getobj__
@@ -0,0 +1,18 @@
1
+ module Asynchronic
2
+ module DataStore
3
+ class NoLazyStore < TransparentProxy
4
+
5
+ include Helper
6
+
7
+ def [](key)
8
+ value = __getobj__[key]
9
+ value.respond_to?(:proxy?) ? value.reload.to_value : value
10
+ end
11
+
12
+ def lazy?
13
+ false
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -1,9 +1,9 @@
1
- require_relative '../transparent_proxy'
2
-
3
1
  module Asynchronic
4
2
  module DataStore
5
3
  class ReadonlyStore < TransparentProxy
6
-
4
+
5
+ include Helper
6
+
7
7
  def []=(key, value)
8
8
  raise "Can't modify read only data store"
9
9
  end
@@ -42,7 +42,7 @@ module Asynchronic
42
42
  end
43
43
 
44
44
  def params
45
- data_store.scoped(:params).readonly
45
+ data_store.scoped(:params).no_lazy.readonly
46
46
  end
47
47
 
48
48
  def result
@@ -89,7 +89,9 @@ module Asynchronic
89
89
  elsif processes.all?(&:completed?)
90
90
  completed!
91
91
  else
92
- processes.select(&:ready?).each(&:enqueue)
92
+ processes.each do |p|
93
+ p.enqueue if p.ready?
94
+ end
93
95
  end
94
96
  end
95
97
 
@@ -1,3 +1,3 @@
1
1
  module Asynchronic
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
data/lib/asynchronic.rb CHANGED
@@ -3,6 +3,7 @@ require 'securerandom'
3
3
  require 'redis'
4
4
  require 'ost'
5
5
  require 'class_config'
6
+ require 'transparent_proxy'
6
7
  require 'logger'
7
8
 
8
9
  Dir.glob(File.expand_path('asynchronic/**/*.rb', File.dirname(__FILE__))).sort.each { |f| require f }
@@ -74,5 +74,21 @@ module DataStoreExamples
74
74
  lazy_value.must_equal 1
75
75
  lazy_value.reload.must_equal 2
76
76
  end
77
+
78
+ it 'No lazy' do
79
+ data_store[:key] = 1
80
+ lazy_store = data_store.lazy
81
+ no_lazy_store = lazy_store.no_lazy
82
+
83
+ data_store.wont_be :lazy?
84
+ lazy_store.must_be :lazy?
85
+ no_lazy_store.wont_be :lazy?
86
+
87
+ no_lazy_store[:key].must_equal 1
88
+
89
+ data_store[:key] = 2
90
+
91
+ no_lazy_store[:key].must_equal 2
92
+ end
77
93
 
78
94
  end
data/spec/expectations.rb CHANGED
@@ -17,7 +17,6 @@ module MiniTest::Assertions
17
17
  process.wont_be :finalized?
18
18
 
19
19
  process.processes.must_be_empty
20
- # process.data.must_be_empty
21
20
  process.error.must_be_nil
22
21
 
23
22
  process.created_at.must_be_instance_of Time
data/spec/jobs.rb CHANGED
@@ -166,4 +166,31 @@ end
166
166
  class WorkerJob < Asynchronic::Job
167
167
  def call
168
168
  end
169
+ end
170
+
171
+ class ForwardReferenceJob < Asynchronic::Job
172
+ def call
173
+ async BuildReferenceJob
174
+ async SendReferenceJob, number: result(BuildReferenceJob)
175
+ result SendReferenceJob
176
+ end
177
+
178
+ class BuildReferenceJob < Asynchronic::Job
179
+ def call
180
+ 1
181
+ end
182
+ end
183
+
184
+ class SendReferenceJob < Asynchronic::Job
185
+ def call
186
+ async UseReferenceJob, number: params[:number]
187
+ result UseReferenceJob
188
+ end
189
+ end
190
+
191
+ class UseReferenceJob < Asynchronic::Job
192
+ def call
193
+ params[:number] + 1
194
+ end
195
+ end
169
196
  end
@@ -340,4 +340,47 @@ module LifeCycleExamples
340
340
  process[ExceptionJob].error.message.must_equal 'Error for test'
341
341
  end
342
342
 
343
+ it 'Forward reference' do
344
+ process = create ForwardReferenceJob
345
+
346
+ process.must_be_initialized
347
+ queue.must_be_empty
348
+
349
+ process.enqueue
350
+
351
+ process.must_be_queued
352
+ queue.must_enqueued process
353
+
354
+ execute queue
355
+
356
+ process.must_be_waiting
357
+ process[ForwardReferenceJob::BuildReferenceJob].must_be_queued
358
+ process[ForwardReferenceJob::SendReferenceJob].must_be_pending
359
+ queue.must_enqueued process[ForwardReferenceJob::BuildReferenceJob]
360
+
361
+ execute queue
362
+
363
+ process.must_be_waiting
364
+ process[ForwardReferenceJob::BuildReferenceJob].must_be_completed
365
+ process[ForwardReferenceJob::SendReferenceJob].must_be_queued
366
+ queue.must_enqueued process[ForwardReferenceJob::SendReferenceJob]
367
+
368
+ execute queue
369
+
370
+ process.must_be_waiting
371
+ process[ForwardReferenceJob::BuildReferenceJob].must_be_completed
372
+ process[ForwardReferenceJob::SendReferenceJob].must_be_waiting
373
+ process[ForwardReferenceJob::SendReferenceJob][ForwardReferenceJob::UseReferenceJob].must_be_queued
374
+ queue.must_enqueued process[ForwardReferenceJob::SendReferenceJob][ForwardReferenceJob::UseReferenceJob]
375
+
376
+ execute queue
377
+
378
+ process.must_be_completed
379
+ process.result.must_equal 2
380
+ process[ForwardReferenceJob::BuildReferenceJob].must_be_completed
381
+ process[ForwardReferenceJob::SendReferenceJob].must_be_completed
382
+ process[ForwardReferenceJob::SendReferenceJob][ForwardReferenceJob::UseReferenceJob].must_be_completed
383
+ queue.must_be_empty
384
+ end
385
+
343
386
  end
metadata CHANGED
@@ -1,176 +1,169 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asynchronic
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.0
4
+ version: 0.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gabriel Naiman
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-06-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: redis
16
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - ~>
17
+ - - "~>"
19
18
  - !ruby/object:Gem::Version
20
19
  version: '3.0'
21
- none: false
22
- requirement: !ruby/object:Gem::Requirement
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.0'
27
- none: false
28
- prerelease: false
29
- type: :runtime
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: ost
32
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: !ruby/object:Gem::Requirement
33
30
  requirements:
34
- - - ~>
31
+ - - "~>"
35
32
  - !ruby/object:Gem::Version
36
33
  version: '0.1'
37
- none: false
38
- requirement: !ruby/object:Gem::Requirement
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
39
37
  requirements:
40
- - - ~>
38
+ - - "~>"
41
39
  - !ruby/object:Gem::Version
42
40
  version: '0.1'
43
- none: false
44
- prerelease: false
45
- type: :runtime
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: class_config
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.0'
48
+ type: :runtime
49
+ prerelease: false
48
50
  version_requirements: !ruby/object:Gem::Requirement
49
51
  requirements:
50
- - - ~>
52
+ - - "~>"
51
53
  - !ruby/object:Gem::Version
52
54
  version: '0.0'
53
- none: false
55
+ - !ruby/object:Gem::Dependency
56
+ name: transparent_proxy
54
57
  requirement: !ruby/object:Gem::Requirement
55
58
  requirements:
56
- - - ~>
59
+ - - "~>"
57
60
  - !ruby/object:Gem::Version
58
61
  version: '0.0'
59
- none: false
60
- prerelease: false
61
62
  type: :runtime
62
- - !ruby/object:Gem::Dependency
63
- name: bundler
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
69
- none: false
68
+ version: '0.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
- - - ~>
73
+ - - "~>"
73
74
  - !ruby/object:Gem::Version
74
75
  version: '1.3'
75
- none: false
76
- prerelease: false
77
76
  type: :development
78
- - !ruby/object:Gem::Dependency
79
- name: rake
77
+ prerelease: false
80
78
  version_requirements: !ruby/object:Gem::Requirement
81
79
  requirements:
82
- - - '>='
80
+ - - "~>"
83
81
  - !ruby/object:Gem::Version
84
- version: '0'
85
- none: false
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
86
85
  requirement: !ruby/object:Gem::Requirement
87
86
  requirements:
88
- - - '>='
87
+ - - ">="
89
88
  - !ruby/object:Gem::Version
90
89
  version: '0'
91
- none: false
92
- prerelease: false
93
90
  type: :development
94
- - !ruby/object:Gem::Dependency
95
- name: minitest
91
+ prerelease: false
96
92
  version_requirements: !ruby/object:Gem::Requirement
97
93
  requirements:
98
- - - ~>
94
+ - - ">="
99
95
  - !ruby/object:Gem::Version
100
- version: '4.7'
101
- none: false
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
102
99
  requirement: !ruby/object:Gem::Requirement
103
100
  requirements:
104
- - - ~>
101
+ - - "~>"
105
102
  - !ruby/object:Gem::Version
106
103
  version: '4.7'
107
- none: false
108
- prerelease: false
109
104
  type: :development
110
- - !ruby/object:Gem::Dependency
111
- name: minitest-great_expectations
105
+ prerelease: false
112
106
  version_requirements: !ruby/object:Gem::Requirement
113
107
  requirements:
114
- - - ~>
108
+ - - "~>"
115
109
  - !ruby/object:Gem::Version
116
- version: '0.0'
117
- none: false
110
+ version: '4.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest-great_expectations
118
113
  requirement: !ruby/object:Gem::Requirement
119
114
  requirements:
120
- - - ~>
115
+ - - "~>"
121
116
  - !ruby/object:Gem::Version
122
117
  version: '0.0'
123
- none: false
124
- prerelease: false
125
118
  type: :development
126
- - !ruby/object:Gem::Dependency
127
- name: turn
119
+ prerelease: false
128
120
  version_requirements: !ruby/object:Gem::Requirement
129
121
  requirements:
130
- - - ~>
122
+ - - "~>"
131
123
  - !ruby/object:Gem::Version
132
- version: '0.9'
133
- none: false
124
+ version: '0.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: turn
134
127
  requirement: !ruby/object:Gem::Requirement
135
128
  requirements:
136
- - - ~>
129
+ - - "~>"
137
130
  - !ruby/object:Gem::Version
138
131
  version: '0.9'
139
- none: false
140
- prerelease: false
141
132
  type: :development
142
- - !ruby/object:Gem::Dependency
143
- name: simplecov
133
+ prerelease: false
144
134
  version_requirements: !ruby/object:Gem::Requirement
145
135
  requirements:
146
- - - '>='
136
+ - - "~>"
147
137
  - !ruby/object:Gem::Version
148
- version: '0'
149
- none: false
138
+ version: '0.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
150
141
  requirement: !ruby/object:Gem::Requirement
151
142
  requirements:
152
- - - '>='
143
+ - - ">="
153
144
  - !ruby/object:Gem::Version
154
145
  version: '0'
155
- none: false
156
- prerelease: false
157
146
  type: :development
158
- - !ruby/object:Gem::Dependency
159
- name: pry
147
+ prerelease: false
160
148
  version_requirements: !ruby/object:Gem::Requirement
161
149
  requirements:
162
- - - '>='
150
+ - - ">="
163
151
  - !ruby/object:Gem::Version
164
152
  version: '0'
165
- none: false
153
+ - !ruby/object:Gem::Dependency
154
+ name: pry
166
155
  requirement: !ruby/object:Gem::Requirement
167
156
  requirements:
168
- - - '>='
157
+ - - ">="
169
158
  - !ruby/object:Gem::Version
170
159
  version: '0'
171
- none: false
172
- prerelease: false
173
160
  type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
174
167
  description: DSL for asynchronic pipeline
175
168
  email:
176
169
  - gabynaiman@gmail.com
@@ -178,9 +171,9 @@ executables: []
178
171
  extensions: []
179
172
  extra_rdoc_files: []
180
173
  files:
181
- - .coveralls.yml
182
- - .gitignore
183
- - .travis.yml
174
+ - ".coveralls.yml"
175
+ - ".gitignore"
176
+ - ".travis.yml"
184
177
  - Gemfile
185
178
  - LICENSE.txt
186
179
  - README.md
@@ -192,6 +185,7 @@ files:
192
185
  - lib/asynchronic/data_store/key.rb
193
186
  - lib/asynchronic/data_store/lazy_store.rb
194
187
  - lib/asynchronic/data_store/lazy_value.rb
188
+ - lib/asynchronic/data_store/no_lazy_store.rb
195
189
  - lib/asynchronic/data_store/readonly_store.rb
196
190
  - lib/asynchronic/data_store/redis.rb
197
191
  - lib/asynchronic/data_store/scoped_store.rb
@@ -202,7 +196,6 @@ files:
202
196
  - lib/asynchronic/queue_engine/in_memory.rb
203
197
  - lib/asynchronic/queue_engine/ost.rb
204
198
  - lib/asynchronic/queue_engine/synchronic.rb
205
- - lib/asynchronic/transparent_proxy.rb
206
199
  - lib/asynchronic/version.rb
207
200
  - lib/asynchronic/worker.rb
208
201
  - spec/coverage_helper.rb
@@ -223,40 +216,32 @@ files:
223
216
  - spec/queue_engine/ost_spec.rb
224
217
  - spec/queue_engine/queue_engine_examples.rb
225
218
  - spec/queue_engine/synchronic_spec.rb
226
- - spec/transparent_proxy_spec.rb
227
219
  - spec/worker/in_memory_spec.rb
228
220
  - spec/worker/redis_spec.rb
229
221
  - spec/worker/worker_examples.rb
230
222
  homepage: https://github.com/gabynaiman/asynchronic
231
223
  licenses:
232
224
  - MIT
233
- post_install_message:
225
+ metadata: {}
226
+ post_install_message:
234
227
  rdoc_options: []
235
228
  require_paths:
236
229
  - lib
237
230
  required_ruby_version: !ruby/object:Gem::Requirement
238
231
  requirements:
239
- - - '>='
232
+ - - ">="
240
233
  - !ruby/object:Gem::Version
241
- segments:
242
- - 0
243
- hash: 2
244
234
  version: '0'
245
- none: false
246
235
  required_rubygems_version: !ruby/object:Gem::Requirement
247
236
  requirements:
248
- - - '>='
237
+ - - ">="
249
238
  - !ruby/object:Gem::Version
250
- segments:
251
- - 0
252
- hash: 2
253
239
  version: '0'
254
- none: false
255
240
  requirements: []
256
- rubyforge_project:
257
- rubygems_version: 1.8.24
258
- signing_key:
259
- specification_version: 3
241
+ rubyforge_project:
242
+ rubygems_version: 2.2.2
243
+ signing_key:
244
+ specification_version: 4
260
245
  summary: DSL for asynchronic pipeline using queues over Redis
261
246
  test_files:
262
247
  - spec/coverage_helper.rb
@@ -277,7 +262,6 @@ test_files:
277
262
  - spec/queue_engine/ost_spec.rb
278
263
  - spec/queue_engine/queue_engine_examples.rb
279
264
  - spec/queue_engine/synchronic_spec.rb
280
- - spec/transparent_proxy_spec.rb
281
265
  - spec/worker/in_memory_spec.rb
282
266
  - spec/worker/redis_spec.rb
283
267
  - spec/worker/worker_examples.rb
@@ -1,52 +0,0 @@
1
- module Asynchronic
2
- class TransparentProxy
3
-
4
- PROXY_METHODS = [:class, :methods, :respond_to?]
5
-
6
- SAFE_METHODS = [:__send__, :__id__, :object_id, :tap] + PROXY_METHODS.map { |m| "proxy_#{m}".to_sym }
7
-
8
- PROXY_METHODS.each { |m| alias_method "proxy_#{m}".to_sym, m }
9
-
10
- instance_methods.reject { |m| SAFE_METHODS.include? m }.
11
- each { |m| undef_method m }
12
-
13
- def inspect
14
- __getobj__.inspect
15
- end
16
-
17
- def proxy_inspect
18
- "#<#{proxy_class} @object=#{inspect}>"
19
- end
20
-
21
- def methods(*args)
22
- proxy_methods(*args) | __getobj__.methods(*args)
23
- end
24
-
25
- def respond_to?(*args)
26
- proxy_respond_to?(*args) || __getobj__.respond_to?(*args)
27
- end
28
-
29
- def proxy?
30
- true
31
- end
32
-
33
- private
34
-
35
- def initialize(object)
36
- __setobj__ object
37
- end
38
-
39
- def __getobj__
40
- @object
41
- end
42
-
43
- def __setobj__(object)
44
- @object = object
45
- end
46
-
47
- def method_missing(method, *args, &block)
48
- __getobj__.send(method, *args, &block)
49
- end
50
-
51
- end
52
- end
@@ -1,36 +0,0 @@
1
- require 'minitest_helper'
2
-
3
- describe Asynchronic::TransparentProxy do
4
-
5
- it 'Transparent' do
6
- proxy = Asynchronic::TransparentProxy.new 1
7
-
8
- proxy.must_equal 1
9
- (proxy + 1).must_equal 2
10
- proxy.class.must_equal Fixnum
11
- proxy.inspect.must_equal 1.inspect
12
- proxy.methods.must_equal proxy.proxy_methods | 1.methods
13
- end
14
-
15
- it 'Proxy methods' do
16
- proxy = Asynchronic::TransparentProxy.new 1
17
-
18
- proxy.must_be :proxy?
19
- proxy.proxy_class.must_equal Asynchronic::TransparentProxy
20
- proxy.proxy_inspect.must_match /#<Asynchronic::TransparentProxy @object=1>/
21
- proxy.proxy_methods.must_include_all [:__send__, :object_id, :tap]
22
- proxy.must_respond_to :proxy_respond_to?
23
- end
24
-
25
- it 'Subclass' do
26
- class NumberProxy < Asynchronic::TransparentProxy
27
- def to_letters
28
- 'one'
29
- end
30
- end
31
-
32
- proxy = NumberProxy.new 1
33
- proxy.to_letters.must_equal 'one'
34
- end
35
-
36
- end