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/lib/asynchronic/hash.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
def with_indiferent_access
|
3
|
-
HashWithIndiferentAccess.new self
|
4
|
-
end
|
5
|
-
end
|
6
|
-
|
7
|
-
class HashWithIndiferentAccess < Hash
|
8
|
-
|
9
|
-
def initialize(hash=nil)
|
10
|
-
merge! hash if hash
|
11
|
-
end
|
12
|
-
|
13
|
-
def [](key)
|
14
|
-
if key?(key) || !transformable_key?(key)
|
15
|
-
super
|
16
|
-
else
|
17
|
-
super transform_key(key)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def transformable_key?(key)
|
24
|
-
key.is_a?(String) || key.is_a?(Symbol)
|
25
|
-
end
|
26
|
-
|
27
|
-
def transform_key(key)
|
28
|
-
key.is_a?(String) ? key.to_sym : key.to_s
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
data/lib/asynchronic/runtime.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
module Asynchronic
|
2
|
-
class Runtime
|
3
|
-
|
4
|
-
attr_reader :process
|
5
|
-
|
6
|
-
def initialize(process)
|
7
|
-
@process = process
|
8
|
-
end
|
9
|
-
|
10
|
-
def evaluate
|
11
|
-
begin
|
12
|
-
@data = process.data
|
13
|
-
process.job.local.each { |k,v| define_singleton_method(k) { v } }
|
14
|
-
instance_eval &process.job.class.implementation
|
15
|
-
ensure
|
16
|
-
process.merge @data
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.evaluate(process)
|
21
|
-
new(process).evaluate
|
22
|
-
end
|
23
|
-
|
24
|
-
private
|
25
|
-
|
26
|
-
def define_job(job_class, options={})
|
27
|
-
defaults = {
|
28
|
-
parent: process.job.lookup.id,
|
29
|
-
queue: job_class.queue || process.queue
|
30
|
-
}
|
31
|
-
|
32
|
-
process.env.build_job job_class, defaults.merge(options)
|
33
|
-
end
|
34
|
-
|
35
|
-
def data
|
36
|
-
@data
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
@@ -1,92 +0,0 @@
|
|
1
|
-
require 'minitest_helper'
|
2
|
-
|
3
|
-
describe Asynchronic::DataStore::Lookup do
|
4
|
-
|
5
|
-
describe 'One level' do
|
6
|
-
|
7
|
-
let(:job) { Asynchronic::Job.new }
|
8
|
-
let(:lookup) { Asynchronic::DataStore::Lookup.new job }
|
9
|
-
|
10
|
-
it 'Id' do
|
11
|
-
lookup.id.must_equal "job:#{job.id}"
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'Status' do
|
15
|
-
lookup.status.must_equal "job:#{job.id}:status"
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'Data' do
|
19
|
-
lookup.data.must_equal "job:#{job.id}:data"
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'Jobs' do
|
23
|
-
lookup.jobs.must_equal "job:#{job.id}:jobs"
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'Error' do
|
27
|
-
lookup.error.must_equal "job:#{job.id}:error"
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'Created At' do
|
31
|
-
lookup.created_at.must_equal "job:#{job.id}:created_at"
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'Queued At' do
|
35
|
-
lookup.queued_at.must_equal "job:#{job.id}:queued_at"
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'Started At' do
|
39
|
-
lookup.started_at.must_equal "job:#{job.id}:started_at"
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'Finalized At' do
|
43
|
-
lookup.finalized_at.must_equal "job:#{job.id}:finalized_at"
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'Two levels' do
|
49
|
-
|
50
|
-
let(:parent) { "job:#{SecureRandom.uuid}" }
|
51
|
-
let(:job) { Asynchronic::Job.new parent: parent }
|
52
|
-
let(:lookup) { Asynchronic::DataStore::Lookup.new job }
|
53
|
-
|
54
|
-
it 'Id' do
|
55
|
-
lookup.id.must_equal "#{parent}:jobs:#{job.id}"
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'Status' do
|
59
|
-
lookup.status.must_equal "#{parent}:jobs:#{job.id}:status"
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'Data' do
|
63
|
-
lookup.data.must_equal "#{parent}:jobs:#{job.id}:data"
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'Jobs' do
|
67
|
-
lookup.jobs.must_equal "#{parent}:jobs:#{job.id}:jobs"
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'Error' do
|
71
|
-
lookup.error.must_equal "#{parent}:jobs:#{job.id}:error"
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'Created At' do
|
75
|
-
lookup.created_at.must_equal "#{parent}:jobs:#{job.id}:created_at"
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'Queued At' do
|
79
|
-
lookup.queued_at.must_equal "#{parent}:jobs:#{job.id}:queued_at"
|
80
|
-
end
|
81
|
-
|
82
|
-
it 'Started At' do
|
83
|
-
lookup.started_at.must_equal "#{parent}:jobs:#{job.id}:started_at"
|
84
|
-
end
|
85
|
-
|
86
|
-
it 'Finalized At' do
|
87
|
-
lookup.finalized_at.must_equal "#{parent}:jobs:#{job.id}:finalized_at"
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|