maestro_plugin 0.0.2 → 0.0.3
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.
- data/.gitignore +0 -1
- data/Gemfile.lock +2 -2
- data/README.md +2 -2
- data/Rakefile +5 -15
- data/lib/maestro_plugin/maestro_worker.rb +37 -8
- data/lib/maestro_plugin/version.rb +1 -1
- data/spec/maestro_worker_spec.rb +42 -16
- metadata +23 -29
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
maestro_plugin (0.0.
|
4
|
+
maestro_plugin (0.0.4)
|
5
5
|
json (>= 1.4.6)
|
6
6
|
logging (= 1.8.0)
|
7
7
|
rubyzip (= 0.9.8)
|
@@ -18,7 +18,7 @@ GEM
|
|
18
18
|
logging (1.8.0)
|
19
19
|
little-plugger (>= 1.1.3)
|
20
20
|
multi_json (>= 1.3.6)
|
21
|
-
multi_json (1.
|
21
|
+
multi_json (1.7.2)
|
22
22
|
rake (10.0.4)
|
23
23
|
rspec (2.13.0)
|
24
24
|
rspec-core (~> 2.13.0)
|
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -4,24 +4,14 @@ require 'rake/clean'
|
|
4
4
|
|
5
5
|
require File.expand_path('../lib/maestro_plugin/version', __FILE__)
|
6
6
|
|
7
|
-
CLEAN.include(
|
7
|
+
CLEAN.include('pkg')
|
8
|
+
CLOBBER.include('.bundle', '.config', 'coverage', 'InstalledFiles', 'spec/reports', 'rdoc', 'test', 'tmp')
|
8
9
|
|
9
|
-
task :default => [:build]
|
10
|
+
task :default => [:clean, :bundle, :spec, :build]
|
10
11
|
|
11
|
-
|
12
|
-
RSpec::Core::RakeTask.new do |t|
|
13
|
-
t.pattern = './spec/**/*_spec.rb' # don't need this, it's default.
|
14
|
-
t.rspec_opts = '--fail-fast --format p --color'
|
15
|
-
# Put spec opts in a file named .rspec in root
|
16
|
-
end
|
12
|
+
RSpec::Core::RakeTask.new
|
17
13
|
|
18
14
|
desc 'Get dependencies with Bundler'
|
19
15
|
task :bundle do
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
task :build => [:clean, :bundle, :spec]
|
24
|
-
task :build do
|
25
|
-
system 'gem build maestro_plugin.gemspec'
|
16
|
+
sh %{bundle install}
|
26
17
|
end
|
27
|
-
|
@@ -129,18 +129,44 @@ module Maestro
|
|
129
129
|
end
|
130
130
|
|
131
131
|
# Sends the specified ouput string to the server for persistence
|
132
|
-
|
133
|
-
|
132
|
+
# If called with :buffer as an option, the output will be queued up until a number of writes has occurred, or
|
133
|
+
# a reasonable period since the last sent occurred.
|
134
|
+
# Any call without the :buffer option will cause any buffered output to be sent immediately.
|
135
|
+
#
|
136
|
+
# Example:
|
137
|
+
# write_output("I am Sam\n") <-- send immediately
|
138
|
+
# write_output("Sam I am\n", :buffer => true) <-- buffer for later
|
139
|
+
# write_output("I like Ham\n") <-- sends 'Sam I am\nI like Ham\n'
|
140
|
+
def write_output(output, options = {})
|
141
|
+
# First time thru? We need to do some setup!
|
142
|
+
reset_buffered_output if @buffered_output.nil?
|
143
|
+
|
144
|
+
# If we have data and its not just a newline add it
|
145
|
+
if output && !output.gsub(/\n/, '').empty?
|
146
|
+
@buffered_output += output
|
147
|
+
end
|
134
148
|
|
135
|
-
|
136
|
-
|
137
|
-
|
149
|
+
# If a) we have data to write, and
|
150
|
+
# b) its been > 2 seconds since we last sent
|
151
|
+
#
|
152
|
+
# The 2 second factor is there to allow slowly accumulating data to be sent out more regularly.
|
153
|
+
if !@buffered_output.empty? && (!options[:buffer] || Time.now - @last_write_output > 2)
|
154
|
+
workitem[OUTPUT_META] = @buffered_output
|
155
|
+
workitem[STREAMING_META] = true
|
156
|
+
send_workitem_message
|
157
|
+
reset_buffered_output
|
158
|
+
end
|
138
159
|
rescue Exception => e
|
139
160
|
Maestro.log.warn "Unable To Write Output To Server #{e.class} #{e}: #{e.backtrace.join("\n")}"
|
140
161
|
ensure
|
141
162
|
workitem.delete(STREAMING_META)
|
142
163
|
end
|
143
164
|
|
165
|
+
def reset_buffered_output
|
166
|
+
@buffered_output = ''
|
167
|
+
@last_write_output = Time.now
|
168
|
+
end
|
169
|
+
|
144
170
|
def error
|
145
171
|
fields[ERROR_META]
|
146
172
|
end
|
@@ -243,10 +269,13 @@ module Maestro
|
|
243
269
|
|
244
270
|
# end persistence
|
245
271
|
|
246
|
-
|
247
|
-
|
272
|
+
# Get a field from workitem, supporting default value
|
273
|
+
def get_field(field, default = nil)
|
274
|
+
value = fields[field]
|
275
|
+
value = default if !default.nil? && (value.nil? || (value.respond_to?(:empty?) && value.empty?))
|
276
|
+
value
|
248
277
|
end
|
249
|
-
|
278
|
+
|
250
279
|
def fields
|
251
280
|
workitem['fields']
|
252
281
|
end
|
data/spec/maestro_worker_spec.rb
CHANGED
@@ -29,7 +29,7 @@ describe Maestro::MaestroWorker do
|
|
29
29
|
before :each do
|
30
30
|
@workitem = {'fields' => {}}
|
31
31
|
@ruote_participants = double("ruote_participants")
|
32
|
-
@ruote_participants.should_receive(:send_workitem_message).with(@workitem)
|
32
|
+
@ruote_participants.should_receive(:send_workitem_message).at_least(:once).with(@workitem)
|
33
33
|
|
34
34
|
@worker = Maestro::MaestroWorker.new
|
35
35
|
@worker.stub(:ruote_participants => @ruote_participants)
|
@@ -37,40 +37,68 @@ describe Maestro::MaestroWorker do
|
|
37
37
|
@worker.should_receive(:send_workitem_message).at_least(:once).and_call_original
|
38
38
|
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it 'should send a write_output message' do
|
42
42
|
@worker.write_output('Some Silly String')
|
43
43
|
@worker.workitem['__output__'].should eql('Some Silly String')
|
44
44
|
@worker.workitem['__streaming__'].should be_nil
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
|
+
it 'should aggregate output' do
|
48
|
+
@worker.write_output('Some Silly String')
|
49
|
+
@worker.workitem['__output__'].should eql('Some Silly String')
|
50
|
+
@worker.workitem['__streaming__'].should be_nil
|
51
|
+
|
52
|
+
@worker.write_output("1", :buffer => true)
|
53
|
+
@worker.workitem['__output__'].should eql('Some Silly String')
|
54
|
+
@worker.workitem['__streaming__'].should be_nil
|
55
|
+
@worker.write_output("22", :buffer => true)
|
56
|
+
@worker.workitem['__output__'].should eql('Some Silly String')
|
57
|
+
@worker.workitem['__streaming__'].should be_nil
|
58
|
+
|
59
|
+
# Should auto-send after 2 second delay
|
60
|
+
sleep 3
|
61
|
+
@worker.write_output("333", :buffer => true)
|
62
|
+
@worker.workitem['__output__'].should eql('122333')
|
63
|
+
@worker.workitem['__streaming__'].should be_nil
|
64
|
+
@worker.write_output("4444", :buffer => true)
|
65
|
+
@worker.workitem['__output__'].should eql('122333')
|
66
|
+
@worker.workitem['__streaming__'].should be_nil
|
67
|
+
|
68
|
+
# When called without aggregate, should purge
|
69
|
+
@worker.write_output("5555")
|
70
|
+
@worker.workitem['__output__'].should eql('44445555')
|
71
|
+
@worker.workitem['__streaming__'].should be_nil
|
72
|
+
end
|
73
|
+
|
47
74
|
it 'should send a not needed message' do
|
48
75
|
@worker.not_needed
|
49
76
|
@worker.workitem['__not_needed__'].should be_nil
|
50
77
|
end
|
51
|
-
|
78
|
+
|
52
79
|
it 'should send a cancel message' do
|
53
80
|
@worker.cancel
|
54
81
|
@worker.workitem['__cancel__'].should be_nil
|
55
82
|
end
|
56
|
-
|
83
|
+
|
57
84
|
it 'should send a set_waiting message' do
|
58
|
-
|
85
|
+
# expects already in before :each block, so putting it here too causes test fail
|
86
|
+
# @ruote_participants.should_receive(:send_workitem_message).with(@workitem)
|
59
87
|
@worker.set_waiting(true)
|
60
88
|
@worker.workitem['__waiting__'].should be_true
|
61
|
-
|
89
|
+
|
62
90
|
@worker.set_waiting(false)
|
63
91
|
@worker.workitem['__waiting__'].should be_nil
|
64
92
|
end
|
65
|
-
|
93
|
+
|
66
94
|
it 'should send a create record message' do
|
67
95
|
@worker.create_record_with_fields('cars', ['manu', 'date', 'name'], ['ferrari', '1964', '250 GTO'])
|
68
|
-
|
96
|
+
|
69
97
|
@worker.workitem['__model__'].should eql('cars')
|
70
98
|
@worker.workitem['__record_fields__'].should eql('manu,date,name')
|
71
99
|
@worker.workitem['__record_values__'].should eql('ferrari,1964,250 GTO')
|
72
100
|
end
|
73
|
-
|
101
|
+
|
74
102
|
it 'should send a create record message with a hash' do
|
75
103
|
fields = {'manu' => 'ferrari', 'date' => '1964', 'name' => 'GTO'}
|
76
104
|
@worker.create_record_with_fields('cars', fields)
|
@@ -80,13 +108,13 @@ describe Maestro::MaestroWorker do
|
|
80
108
|
|
81
109
|
it 'should send an update record-field message' do
|
82
110
|
@worker.update_fields_in_record('animal', 'donkey', 'name', 'e-or')
|
83
|
-
|
111
|
+
|
84
112
|
@worker.workitem['__model__'].should eql('animal')
|
85
113
|
@worker.workitem['__record_id__'].should eql('donkey')
|
86
114
|
@worker.workitem['__record_field__'].should eql('name')
|
87
115
|
@worker.workitem['__record_value__'].should eql('e-or')
|
88
116
|
end
|
89
|
-
|
117
|
+
|
90
118
|
it 'should send a delete record message' do
|
91
119
|
@worker.delete_record('animal', 1)
|
92
120
|
@worker.workitem['__model__'].should eql('animal')
|
@@ -101,8 +129,8 @@ describe Maestro::MaestroWorker do
|
|
101
129
|
@worker.workitem['__filter__'].should eql(filter)
|
102
130
|
@worker.workitem['__name__'].should be_nil
|
103
131
|
end
|
104
|
-
end
|
105
|
-
|
132
|
+
end
|
133
|
+
|
106
134
|
describe 'Field handling' do
|
107
135
|
before :each do
|
108
136
|
@worker = Maestro::MaestroWorker.new
|
@@ -136,7 +164,5 @@ describe Maestro::MaestroWorker do
|
|
136
164
|
@worker.is_json?('a string').should be_false
|
137
165
|
end
|
138
166
|
|
139
|
-
|
140
|
-
|
141
167
|
end
|
142
168
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: maestro_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Etienne Pelletier
|
@@ -10,85 +10,85 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2013-04-
|
13
|
+
date: 2013-04-23 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: logging
|
17
|
-
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
19
|
none: false
|
19
20
|
requirements:
|
20
21
|
- - "="
|
21
22
|
- !ruby/object:Gem::Version
|
22
23
|
version: 1.8.0
|
23
|
-
requirement: *id001
|
24
|
-
prerelease: false
|
25
24
|
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rubyzip
|
28
|
-
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
30
|
none: false
|
30
31
|
requirements:
|
31
32
|
- - "="
|
32
33
|
- !ruby/object:Gem::Version
|
33
34
|
version: 0.9.8
|
34
|
-
requirement: *id002
|
35
|
-
prerelease: false
|
36
35
|
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: json
|
39
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
41
|
none: false
|
41
42
|
requirements:
|
42
43
|
- - ">="
|
43
44
|
- !ruby/object:Gem::Version
|
44
45
|
version: 1.4.6
|
45
|
-
requirement: *id003
|
46
|
-
prerelease: false
|
47
46
|
type: :runtime
|
47
|
+
version_requirements: *id003
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: bundler
|
50
|
-
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
52
|
none: false
|
52
53
|
requirements:
|
53
54
|
- - ~>
|
54
55
|
- !ruby/object:Gem::Version
|
55
56
|
version: "1.3"
|
56
|
-
requirement: *id004
|
57
|
-
prerelease: false
|
58
57
|
type: :development
|
58
|
+
version_requirements: *id004
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: rake
|
61
|
-
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
63
|
none: false
|
63
64
|
requirements:
|
64
65
|
- - ">="
|
65
66
|
- !ruby/object:Gem::Version
|
66
67
|
version: "0"
|
67
|
-
requirement: *id005
|
68
|
-
prerelease: false
|
69
68
|
type: :development
|
69
|
+
version_requirements: *id005
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: jruby-openssl
|
72
|
-
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
74
|
none: false
|
74
75
|
requirements:
|
75
76
|
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: "0"
|
78
|
-
requirement: *id006
|
79
|
-
prerelease: false
|
80
79
|
type: :development
|
80
|
+
version_requirements: *id006
|
81
81
|
- !ruby/object:Gem::Dependency
|
82
82
|
name: rspec
|
83
|
-
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
84
85
|
none: false
|
85
86
|
requirements:
|
86
87
|
- - ~>
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: 2.13.0
|
89
|
-
requirement: *id007
|
90
|
-
prerelease: false
|
91
90
|
type: :development
|
91
|
+
version_requirements: *id007
|
92
92
|
description: A ruby library to help with the creation of Maestro plugins
|
93
93
|
email:
|
94
94
|
- epelletier@maestrodev.com
|
@@ -126,18 +126,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
hash: 2
|
130
|
-
segments:
|
131
|
-
- 0
|
132
129
|
version: "0"
|
133
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
131
|
none: false
|
135
132
|
requirements:
|
136
133
|
- - ">="
|
137
134
|
- !ruby/object:Gem::Version
|
138
|
-
hash: 2
|
139
|
-
segments:
|
140
|
-
- 0
|
141
135
|
version: "0"
|
142
136
|
requirements: []
|
143
137
|
|