nestene 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/TODO.txt +2 -0
- data/features/support/env.rb +1 -0
- data/lib/nestene/actor/auton_queue.rb +36 -20
- data/lib/nestene/actor/auton_storage.rb +7 -0
- data/lib/nestene/actor/core.rb +4 -2
- data/lib/nestene/actor/delayed_scheduler.rb +8 -5
- data/lib/nestene/auton_context.rb +4 -2
- data/lib/nestene/storage.rb +23 -6
- data/lib/nestene/version.rb +1 -1
- data/spec/nestene/storage_spec.rb +44 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dc00c22cd4e58cd1a82ac111d8531cd31ffa244
|
4
|
+
data.tar.gz: 35aa72d30e3c2d36b3b48245bffee533cd9e12b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8203a4de036bd60499bd616201969e37678a74a0cdf972884bd1db4a7a17dee6708be152ba168310c469477c86cdb4789f8738fda76063ebfcb4a808f36df97d
|
7
|
+
data.tar.gz: dac861c5b236c5c8a788e54d528b643e8e3bf58c3e36a634c49dbbf3fac773ef43b460d0624f02184333e8baf321453e1ba0a3541ec515c2f25ef49b56b54c2e
|
data/TODO.txt
CHANGED
data/features/support/env.rb
CHANGED
@@ -12,24 +12,38 @@ module Nestene
|
|
12
12
|
|
13
13
|
|
14
14
|
def execute_next_step topic, auton_id, state
|
15
|
+
|
16
|
+
return unless state
|
17
|
+
|
15
18
|
executing = nil
|
16
19
|
type = nil
|
17
20
|
ser = nil
|
18
21
|
running = false
|
19
22
|
|
20
|
-
Celluloid::Actor["storage:%s" % auton_id]
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
storage_actor = Celluloid::Actor["storage:%s" % auton_id]
|
24
|
+
|
25
|
+
return unless storage_actor
|
26
|
+
|
27
|
+
storage_actor.update do |state|
|
28
|
+
if state
|
29
|
+
running = state.state == :ready && !state.queue.to_execute.empty?
|
30
|
+
if running
|
31
|
+
nx = state.queue.to_execute.shift
|
32
|
+
executing = ExecutingMethod.new(nx)
|
33
|
+
state.queue.currently_executing = executing
|
34
|
+
type = state.type
|
35
|
+
ser = state.serialized
|
36
|
+
end
|
28
37
|
end
|
29
38
|
end
|
30
39
|
|
31
40
|
return unless running
|
32
41
|
|
42
|
+
if executing.name == '__terminate_this_auton'
|
43
|
+
Celluloid::Actor["storage:%s" % auton_id].async.shutdown
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
33
47
|
instance = Nestene::class_from_string(type).from_structure(ser)
|
34
48
|
|
35
49
|
if instance.public_methods.include?(:context=)
|
@@ -65,20 +79,22 @@ module Nestene
|
|
65
79
|
end
|
66
80
|
|
67
81
|
Celluloid::Actor["storage:%s" % auton_id].update do |state|
|
68
|
-
state
|
69
|
-
|
70
|
-
|
71
|
-
if
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
82
|
+
if state
|
83
|
+
state.queue.currently_executing = nil
|
84
|
+
state.serialized = instance.to_structure
|
85
|
+
if exception
|
86
|
+
if instance.methods.include?(:handle_exception) && executing.name != :handle_exception
|
87
|
+
method = ScheduledMethod.new
|
88
|
+
method.name = :handle_exception
|
89
|
+
method.parameters = [exception.class.name, exception.message, executing.name, executing.parameters]
|
90
|
+
method.uuid = SecureRandom.uuid
|
91
|
+
state.queue.to_execute.unshift method
|
92
|
+
else
|
93
|
+
state.queue.failed = true
|
94
|
+
end
|
79
95
|
end
|
96
|
+
state.queue.add_executed executed
|
80
97
|
end
|
81
|
-
state.queue.add_executed executed
|
82
98
|
end
|
83
99
|
end
|
84
100
|
|
@@ -36,6 +36,13 @@ module Nestene
|
|
36
36
|
structure ? AutonState.from_structure(structure) : nil
|
37
37
|
end
|
38
38
|
|
39
|
+
def shutdown
|
40
|
+
Celluloid::Actor.delete("storage:%s" % @auton_id)
|
41
|
+
@storage.delete(@auton_id)
|
42
|
+
publish('state_update', @auton_id, nil)
|
43
|
+
terminate
|
44
|
+
end
|
45
|
+
|
39
46
|
def update &block
|
40
47
|
before = @storage.load(@auton_id)
|
41
48
|
state = AutonState.from_structure(@storage.load(@auton_id))
|
data/lib/nestene/actor/core.rb
CHANGED
@@ -138,8 +138,10 @@ module Nestene
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def notify_waiters topic, auton_id, state
|
141
|
-
|
142
|
-
|
141
|
+
if state
|
142
|
+
future = @execution_futures.delete(auton_id)
|
143
|
+
future.signal(SelfValue.new) if future
|
144
|
+
end
|
143
145
|
end
|
144
146
|
|
145
147
|
end
|
@@ -22,13 +22,16 @@ module Nestene
|
|
22
22
|
|
23
23
|
@schedule.delete_if{|e| e.first == auton_id}
|
24
24
|
|
25
|
-
state
|
26
|
-
|
27
|
-
|
25
|
+
if state
|
26
|
+
|
27
|
+
state.queue.delayed.each do |d|
|
28
|
+
@schedule << [auton_id, d]
|
29
|
+
end
|
28
30
|
|
29
|
-
|
31
|
+
@schedule.sort_by!{|e| e[1].execute_at}
|
30
32
|
|
31
|
-
|
33
|
+
async.schedule_methods
|
34
|
+
end
|
32
35
|
|
33
36
|
end
|
34
37
|
|
data/lib/nestene/storage.rb
CHANGED
@@ -32,12 +32,16 @@ module Nestene
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def store(key, value)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
if value != nil
|
36
|
+
final_name = "%s/%s" % [@dir,@converter.key_to_file_name(key)]
|
37
|
+
tmp_name = "%s.temp" % final_name
|
38
|
+
File.open(tmp_name,"w") do |f|
|
39
|
+
f.write(JSON.pretty_generate(value))
|
40
|
+
end
|
41
|
+
File.rename(tmp_name, final_name)
|
42
|
+
else
|
43
|
+
delete(key)
|
39
44
|
end
|
40
|
-
File.rename(tmp_name, final_name)
|
41
45
|
end
|
42
46
|
|
43
47
|
def load(key)
|
@@ -49,6 +53,11 @@ module Nestene
|
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
56
|
+
def delete(key)
|
57
|
+
file_name = "%s/%s" % [@dir,@converter.key_to_file_name(key)]
|
58
|
+
File.unlink(file_name)
|
59
|
+
end
|
60
|
+
|
52
61
|
end
|
53
62
|
|
54
63
|
class MemoryStorage
|
@@ -66,7 +75,15 @@ module Nestene
|
|
66
75
|
end
|
67
76
|
|
68
77
|
def store(key, value)
|
69
|
-
|
78
|
+
if value != nil
|
79
|
+
@storage[key] = value
|
80
|
+
else
|
81
|
+
delete(key)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def delete(key)
|
86
|
+
@storage.delete(key)
|
70
87
|
end
|
71
88
|
end
|
72
89
|
|
data/lib/nestene/version.rb
CHANGED
@@ -23,9 +23,9 @@ module Nestene
|
|
23
23
|
|
24
24
|
after{FileUtils.remove_entry_secure tmpdir}
|
25
25
|
|
26
|
-
|
26
|
+
subject {DiskStorage.new(tmpdir)}
|
27
27
|
|
28
|
-
|
28
|
+
describe :list do
|
29
29
|
|
30
30
|
context "when there is nothing in the storage" do
|
31
31
|
it "should return empty list" do
|
@@ -44,8 +44,6 @@ module Nestene
|
|
44
44
|
|
45
45
|
describe :load do
|
46
46
|
|
47
|
-
subject {DiskStorage.new(tmpdir)}
|
48
|
-
|
49
47
|
context "when the object does not exist" do
|
50
48
|
it "should return nil" do
|
51
49
|
expect(subject.load('whatever')).to be_nil
|
@@ -62,20 +60,37 @@ module Nestene
|
|
62
60
|
end
|
63
61
|
|
64
62
|
describe :store do
|
65
|
-
|
66
|
-
|
67
|
-
it "stores structure" do
|
63
|
+
it "should store structure" do
|
68
64
|
subject.store('test',{})
|
69
65
|
expect(subject.load('test')).to eq({})
|
70
66
|
end
|
67
|
+
|
68
|
+
context "when structure is nil" do
|
69
|
+
it 'should delete the entry' do
|
70
|
+
subject.store('test',{})
|
71
|
+
subject.store('test',nil)
|
72
|
+
expect(subject.load('test')).to eq(nil)
|
73
|
+
expect(subject.list).to_not include('test')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe :delete do
|
79
|
+
it "deletes existing strucuture" do
|
80
|
+
subject.store('test',{})
|
81
|
+
subject.delete('test')
|
82
|
+
expect(subject.load('test')).to eq(nil)
|
83
|
+
expect(subject.list).to_not include('test')
|
84
|
+
end
|
71
85
|
end
|
72
86
|
|
73
87
|
end
|
74
88
|
|
75
89
|
describe MemoryStorage do
|
76
|
-
describe :list do
|
77
90
|
|
78
|
-
|
91
|
+
subject {MemoryStorage.new}
|
92
|
+
|
93
|
+
describe :list do
|
79
94
|
|
80
95
|
context "when there is nothing in the storage" do
|
81
96
|
it "should return empty list" do
|
@@ -85,7 +100,6 @@ module Nestene
|
|
85
100
|
|
86
101
|
context "when there is at least one object in the storage" do
|
87
102
|
before {subject.store("test",{})}
|
88
|
-
|
89
103
|
it "should return list of existing objects" do
|
90
104
|
expect(subject.list).to eq(['test'])
|
91
105
|
end
|
@@ -93,9 +107,6 @@ module Nestene
|
|
93
107
|
end
|
94
108
|
|
95
109
|
describe :load do
|
96
|
-
|
97
|
-
subject {MemoryStorage.new}
|
98
|
-
|
99
110
|
context "when the object does not exist" do
|
100
111
|
it "should return nil" do
|
101
112
|
expect(subject.load('whatever')).to be_nil
|
@@ -108,17 +119,33 @@ module Nestene
|
|
108
119
|
expect(subject.load('test')).to eq({})
|
109
120
|
end
|
110
121
|
end
|
111
|
-
|
112
122
|
end
|
113
123
|
|
114
124
|
|
115
125
|
describe :store do
|
116
|
-
|
117
|
-
|
118
|
-
it "stores structure" do
|
126
|
+
it "should store structure" do
|
119
127
|
subject.store('test',{})
|
120
128
|
expect(subject.load('test')).to eq({})
|
121
129
|
end
|
130
|
+
|
131
|
+
context "when structure is nil" do
|
132
|
+
it 'should delete the entry' do
|
133
|
+
subject.store('test',{})
|
134
|
+
subject.store('test',nil)
|
135
|
+
expect(subject.load('test')).to eq(nil)
|
136
|
+
expect(subject.list).to_not include('test')
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
describe :delete do
|
143
|
+
it "deletes existing strucuture" do
|
144
|
+
subject.store('test',{})
|
145
|
+
subject.delete('test')
|
146
|
+
expect(subject.load('test')).to eq(nil)
|
147
|
+
expect(subject.list).to_not include('test')
|
148
|
+
end
|
122
149
|
end
|
123
150
|
|
124
151
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nestene
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dragan Milic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|