simplews 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.1.5 2008-10-28
2
+
3
+ * 1 major enhancement:
4
+ * Jobs save their states across reboots of the server
5
+
1
6
  == 1.1.4 2008-10-28
2
7
 
3
8
  * 1 major enhancement:
data/Manifest.txt CHANGED
@@ -3,10 +3,8 @@ Manifest.txt
3
3
  PostInstall.txt
4
4
  README.rdoc
5
5
  Rakefile
6
- TestWS.wsdl
7
6
  config/hoe.rb
8
7
  config/requirements.rb
9
- lib/helper.rb
10
8
  lib/simplews.rb
11
9
  lib/simplews/asynchronous.rb
12
10
  lib/simplews/version.rb
@@ -1,4 +1,6 @@
1
1
  require File.join(File.dirname(File.dirname(__FILE__)) + '/simplews')
2
+
3
+ require 'yaml'
2
4
  class SimpleWS::Asynchronous < SimpleWS
3
5
 
4
6
  class JobNotFound < Exception; end
@@ -6,10 +8,6 @@ class SimpleWS::Asynchronous < SimpleWS
6
8
 
7
9
 
8
10
  class Job < Thread
9
-
10
- @@jobs = {}
11
- attr_reader :status, :messages, :name, :results
12
-
13
11
  def self.random_name(s="", num=20)
14
12
  num.times{
15
13
  r = rand
@@ -43,12 +41,20 @@ class SimpleWS::Asynchronous < SimpleWS
43
41
  end
44
42
 
45
43
  def self.job(name)
46
- raise JobNotFound, "Job with name '#{ name }' was not found" if @@jobs[name].nil?
44
+ if @@jobs[name].nil?
45
+ if File.exists?(File.join(@@workdir, ".save/#{name}.yaml"))
46
+ job = Job.new(name, [])
47
+ job.load
48
+ @@jobs[name] = job
49
+ else
50
+ raise JobNotFound, "Job with name '#{ name }' was not found"
51
+ end
52
+ end
47
53
  @@jobs[name]
48
54
  end
49
55
 
50
- def self.start(name, workdir, results, &block)
51
- job = Job.new(name, workdir, results, &block)
56
+ def self.start(name, results, &block)
57
+ job = Job.new(name, results, &block)
52
58
  @@jobs[job.name] = job
53
59
  job.name
54
60
  end
@@ -58,48 +64,97 @@ class SimpleWS::Asynchronous < SimpleWS
58
64
  end
59
65
 
60
66
 
67
+ @@workdir = nil
68
+ @@jobs = {}
69
+
70
+ def self.workdir
71
+ @@workdir
72
+ end
61
73
 
62
- attr_reader :workdir, :messages, :status, :name
63
- def initialize(name, workdir, results, &block)
74
+ def self.workdir=(workdir)
75
+ @@workdir = workdir
76
+ begin
77
+ FileUtils.mkdir(@@workdir) unless File.exist?( @@workdir)
78
+ FileUtils.mkdir(File.join(@@workdir,'.save')) unless File.exist?( File.join(@@workdir,'.save'))
79
+ rescue
80
+ puts "Error creating work directory:"
81
+ raise $!
82
+ end
83
+ end
84
+
85
+ attr_reader :messages, :status, :name
86
+ def initialize(name, results, &block)
64
87
  @status = ''
65
88
  @messages = []
66
89
  @name = Job::make_name(name)
67
90
  @results = results
68
91
  @results_hash = {}
69
- @workdir = workdir
70
-
71
- super do
72
- begin
73
- block.call
74
- step(:done)
75
-
76
- exit
77
- rescue JobAborted
78
- step(:aborted, $!.message)
79
- rescue
80
- error($!.message)
81
- raise $!
92
+
93
+ if block_given?
94
+ super do
95
+ begin
96
+ block.call
97
+ step(:done)
98
+
99
+ rescue SimpleWS::Asynchronous::JobAborted
100
+ step(:aborted, $!.message)
101
+ rescue Exception
102
+ error($!.message)
103
+ raise $!
104
+ ensure
105
+ save
106
+ Thread.exit
107
+ end
82
108
  end
109
+ else
110
+ super do end
83
111
  end
84
112
  end
85
113
 
114
+ def save
115
+ info = {
116
+ :status => @status,
117
+ :messages => @messages,
118
+ :name => @name,
119
+ :results => @results,
120
+ :results_hash => @results_hash,
121
+ }
122
+
123
+ fout = File.open(File.join(@@workdir, ".save/#{name}.yaml"),'w')
124
+ fout.write info.to_yaml
125
+ fout.close
126
+ end
127
+
128
+ def load
129
+ info = YAML::load(File.open(File.join(@@workdir, ".save/#{@name}.yaml")))
130
+ @status = info[:status]
131
+ @messages = info[:messages]
132
+ @name = info[:name]
133
+ @results = info[:results]
134
+ @results_hash = info[:results_hash]
135
+ end
136
+
86
137
  #{{{ Instance methods
138
+ def name
139
+ @name
140
+ end
141
+
87
142
  def step(status, message="")
88
143
  @status = status
89
144
  @messages << message if message != ""
90
145
  end
91
146
 
92
147
  def read(path)
93
- File.open(File.join(@workdir, path)).read
148
+ File.open(File.join(@@workdir, path)).read
94
149
  end
95
150
 
96
151
  def write(path, content)
97
- f = File.open(File.join(@workdir, path),'w')
152
+ f = File.open(File.join(@@workdir, path),'w')
98
153
  f.write(content)
99
154
  f.close
100
155
  end
101
156
 
102
- # Results
157
+ #{{{ Results Related
103
158
  def results=(list)
104
159
  @results = list
105
160
  end
@@ -114,15 +169,16 @@ class SimpleWS::Asynchronous < SimpleWS
114
169
 
115
170
  def result(res_name)
116
171
  raise ArgumentError, "Result #{ res_name } not found" if @results_hash[res_name].nil?
117
- File.open(File.join(@workdir, @results_hash[res_name])).read
172
+ File.open(File.join(@@workdir, @results_hash[res_name])).read
118
173
  end
119
174
 
175
+ #{{{ Status related
120
176
  def status
121
177
  @status.to_s
122
178
  end
123
179
 
124
180
  def done?
125
- @status.to_sym == :done || @status.to_sym == :error
181
+ @status.to_sym == :done || @status.to_sym == :error || @status.to_sym == :aborted
126
182
  end
127
183
 
128
184
  def error?
@@ -134,7 +190,7 @@ class SimpleWS::Asynchronous < SimpleWS
134
190
  end
135
191
 
136
192
  def abort
137
- raise(JobAborted.new)
193
+ raise SimpleWS::Asynchronous::JobAborted, "Aborted"
138
194
  nil
139
195
  end
140
196
 
@@ -145,8 +201,57 @@ class SimpleWS::Asynchronous < SimpleWS
145
201
 
146
202
  end
147
203
 
204
+ ############################################################################################3
148
205
  #{{{ Server
149
206
 
207
+ def set_workdir(workdir)
208
+ Job::workdir = workdir
209
+ end
210
+
211
+ def workdir
212
+ Job::workdir
213
+ end
214
+
215
+ def start_job(name, results = [], &block)
216
+ Job.start(name, results, &block)
217
+ end
218
+
219
+ def set_results(name, results)
220
+ Job.job(name).results = results
221
+ end
222
+
223
+
224
+
225
+ #{{{ Thread helper methods
226
+ def save
227
+ Thread.current.save
228
+ end
229
+
230
+
231
+ def write(*args)
232
+ Thread.current.write(*args)
233
+ end
234
+
235
+ def step(*args)
236
+ Thread.current.step(*args)
237
+ end
238
+
239
+ def read(*args)
240
+ Thread.current.read(*args)
241
+ end
242
+
243
+ def job_name
244
+ Thread.current.name
245
+ end
246
+
247
+ def abort_process
248
+ Thread.current.abort
249
+ end
250
+
251
+
252
+
253
+ #{{{ WS Methods
254
+
150
255
  def status(name)
151
256
  Job.job(name).status
152
257
  end
@@ -178,39 +283,6 @@ class SimpleWS::Asynchronous < SimpleWS
178
283
  def result(name, result)
179
284
  Job.job(name).result(result)
180
285
  end
181
-
182
- def start_job(name, results = [], &block)
183
- Job.start(name, @workdir, results, &block)
184
- end
185
-
186
- def workdir
187
- @workdir
188
- end
189
-
190
- def set_workdir(workdir)
191
- @workdir = workdir
192
- begin
193
- FileUtils.mkdir(@workdir) unless File.exist?( @workdir)
194
- rescue
195
- puts "Error creating work directory:"
196
- raise $!
197
- end
198
- end
199
-
200
- #{{{ Thread helper methods
201
-
202
- def write(*args)
203
- Thread.current.write(*args)
204
- end
205
-
206
- def step(*args)
207
- Thread.current.step(*args)
208
- end
209
-
210
- def read(*args)
211
- Thread.current.read(*args)
212
- end
213
-
214
286
 
215
287
 
216
288
  def initialize(name="WS", description="", host="localhost", port="1984", workdir=nil, *args)
@@ -2,7 +2,7 @@ module Simplews
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  self
@@ -11,7 +11,7 @@ class TestSimpleWS < Test::Unit::TestCase
11
11
  def process(name)
12
12
  name = start_job(name, %w(test.txt)) do
13
13
  begin
14
- write('test.txt', 'Hi')
14
+ write('test.txt', job_name)
15
15
  step(:init)
16
16
  sleep 2
17
17
  step(:step1, "Step1")
@@ -31,13 +31,13 @@ class TestSimpleWS < Test::Unit::TestCase
31
31
  def initialize(*args)
32
32
  super(*args)
33
33
  serve :process, %w(name), :name => :string, :return => :string
34
-
35
34
  end
36
35
  end
37
36
 
38
37
 
39
38
  def setup
40
39
  server = TestAWS.new("TestAWS", "Asynchronous Job Server", 'localhost', '1984')
40
+ server.set_workdir("tmp-TestAWS")
41
41
 
42
42
  Thread.new do
43
43
  server.start
@@ -51,7 +51,8 @@ class TestSimpleWS < Test::Unit::TestCase
51
51
 
52
52
  driver = SimpleWS.get_driver('http://localhost:1984', 'TestAWS')
53
53
 
54
- name = driver.process("test-AWS")
54
+ name = driver.process("")
55
+
55
56
 
56
57
 
57
58
  puts "Job name #{ name }"
@@ -66,7 +67,7 @@ class TestSimpleWS < Test::Unit::TestCase
66
67
  assert(driver.results(name).length == 1)
67
68
 
68
69
  result = driver.results(name).first
69
- assert(driver.result(name, result) == 'Hi')
70
+ assert_match(name, driver.result(name, result))
70
71
 
71
72
 
72
73
  name = driver.process("test-AWS")
@@ -75,7 +76,12 @@ class TestSimpleWS < Test::Unit::TestCase
75
76
  driver.abort(name)
76
77
  sleep 2
77
78
  puts driver.status(name)
78
- assert(!driver.aborted(name))
79
+ assert(driver.aborted(name))
80
+
81
+ FileUtils.cp "tmp-TestAWS/.save/test-AWS.yaml", "tmp-TestAWS/.save/copy-AWS.yaml"
82
+ assert(driver.aborted("copy-AWS"))
83
+
84
+
79
85
  end
80
86
 
81
87
 
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
 
3
+
3
4
  class TestSimpleWS < Test::Unit::TestCase
4
5
 
5
6
  class TestWS < SimpleWS
@@ -14,6 +15,7 @@ class TestSimpleWS < Test::Unit::TestCase
14
15
  serve :bye, %w(name), :name => :string, :return => :string do |name|
15
16
  "Bye bye #{name}. See you soon."
16
17
  end
18
+
17
19
  end
18
20
  end
19
21
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplews
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-07 00:00:00 +01:00
12
+ date: 2008-11-24 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -40,10 +40,8 @@ files:
40
40
  - PostInstall.txt
41
41
  - README.rdoc
42
42
  - Rakefile
43
- - TestWS.wsdl
44
43
  - config/hoe.rb
45
44
  - config/requirements.rb
46
- - lib/helper.rb
47
45
  - lib/simplews.rb
48
46
  - lib/simplews/asynchronous.rb
49
47
  - lib/simplews/version.rb
data/TestWS.wsdl DELETED
@@ -1,112 +0,0 @@
1
- <?xml version="1.0"?>
2
- <definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
3
- xmlns:tns="TestWS-NS"
4
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6
- xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
7
- xmlns:si="http://soapinterop.org/xsd"
8
- xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
9
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
10
- xmlns="http://schemas.xmlsoap.org/wsdl/"
11
- targetNamespace="TestWS-NS">
12
-
13
-
14
- <types>
15
- <schema xmlns="http://www.w3.org/2001/XMLSchema"
16
- targetNamespace="TestWS-NS"
17
- xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
18
- xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
19
- <complexType name="ArrayOfString">
20
- <complexContent>
21
- <restriction base="soapenc:Array">
22
- <attribute ref="soapenc:arrayType"
23
- wsdl:arrayType="string[]"/>
24
- </restriction>
25
- </complexContent>
26
- </complexType>
27
- </schema>
28
- </types>
29
-
30
- <message name="wsdlRequest">
31
- </message>
32
-
33
- <message name="wsdlResponse">
34
- <part type="xsd:string" name="return"/>
35
- </message>
36
-
37
- <message name="hiRequest">
38
- <part type="xsd:string" name="name"/>
39
- </message>
40
-
41
- <message name="hiResponse">
42
- <part type="xsd:string" name="return"/>
43
- </message>
44
-
45
- <message name="byeRequest">
46
- <part type="xsd:string" name="name"/>
47
- </message>
48
-
49
- <message name="byeResponse">
50
- <part type="xsd:string" name="return"/>
51
- </message>
52
-
53
- <portType name="TestWS">
54
- <operation name="wsdl">
55
- <input message="wsdlRequest"/>
56
- <output message="wsdlResponse"/>
57
- </operation>
58
-
59
- <operation name="hi">
60
- <input message="hiRequest"/>
61
- <output message="hiResponse"/>
62
- </operation>
63
-
64
- <operation name="bye">
65
- <input message="byeRequest"/>
66
- <output message="byeResponse"/>
67
- </operation>
68
-
69
- </portType>
70
-
71
- <binding name="TestWSBinding" type="tns:TestWS">
72
- <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
73
- <operation name="wsdl">
74
- <soap:operation soapAction="urn:TestWS#wsdl" style="rpc"/>
75
- <input>
76
- <soap:body namespace="urn:TestWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
77
- </input>
78
- <output>
79
- <soap:body namespace="urn:TestWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
80
- </output>
81
- </operation>
82
-
83
- <operation name="hi">
84
- <soap:operation soapAction="urn:TestWS#hi" style="rpc"/>
85
- <input>
86
- <soap:body namespace="urn:TestWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
87
- </input>
88
- <output>
89
- <soap:body namespace="urn:TestWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
90
- </output>
91
- </operation>
92
-
93
- <operation name="bye">
94
- <soap:operation soapAction="urn:TestWS#bye" style="rpc"/>
95
- <input>
96
- <soap:body namespace="urn:TestWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
97
- </input>
98
- <output>
99
- <soap:body namespace="urn:TestWS" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="encoded"/>
100
- </output>
101
- </operation>
102
-
103
- </binding>
104
- <service name="TestWS">
105
- <documentation>Greeting Services</documentation>
106
-
107
- <port name="TestWS" binding="tns:TestWSBinding">
108
- <soap:address location="http://localhost:1984"/>
109
- </port>
110
- </service>
111
-
112
- </definitions>
data/lib/helper.rb DELETED
File without changes