simplews 1.9.1 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/start_jobs_ws +2 -2
- data/lib/simplews.rb +5 -1
- data/lib/simplews/notifier.rb +123 -0
- metadata +33 -17
data/bin/start_jobs_ws
CHANGED
@@ -28,8 +28,8 @@ OptionParser.new do |opts|
|
|
28
28
|
options[:wsdl] = filename
|
29
29
|
end
|
30
30
|
|
31
|
-
opts.on("-
|
32
|
-
options[:
|
31
|
+
opts.on("-t", "--path PATH", String, "Work directory for the WS") do |filename|
|
32
|
+
options[:directory] = filename
|
33
33
|
end
|
34
34
|
|
35
35
|
end.parse!
|
data/lib/simplews.rb
CHANGED
@@ -71,7 +71,7 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
71
71
|
tmp = File.open("/tmp/simpleWS.wsdl",'w')
|
72
72
|
tmp.write SimpleWS::get_wsdl(url, name)
|
73
73
|
tmp.close
|
74
|
-
driver = SOAP::WSDLDriverFactory.new(
|
74
|
+
driver = SOAP::WSDLDriverFactory.new("/tmp/simpleWS.wsdl").create_rpc_driver
|
75
75
|
FileUtils.rm "/tmp/simpleWS.wsdl"
|
76
76
|
|
77
77
|
driver
|
@@ -216,6 +216,8 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
216
216
|
wsdl.gsub!(/\$\{LOCATION\}/,"http://#{ @host }:#{ @port }")
|
217
217
|
|
218
218
|
if filename
|
219
|
+
directory = File.dirname(File.expand_path(filename))
|
220
|
+
FileUtils.mkdir_p directory unless File.exists? directory
|
219
221
|
File.open(filename,'w') {|f| f.write wsdl }
|
220
222
|
nil
|
221
223
|
else
|
@@ -277,6 +279,8 @@ class SimpleWS < SOAP::RPC::StandaloneServer
|
|
277
279
|
end
|
278
280
|
|
279
281
|
if filename
|
282
|
+
directory = File.dirname(File.expand_path(filename))
|
283
|
+
FileUtils.mkdir_p directory unless File.exists? directory
|
280
284
|
File.open(filename,'w') {|f| f.write html_table }
|
281
285
|
nil
|
282
286
|
else
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'rmail'
|
2
|
+
require 'net/smtp'
|
3
|
+
require 'soap/wsdlDriver'
|
4
|
+
require 'simplews/jobs'
|
5
|
+
|
6
|
+
class SimpleWS::Jobs::Notifier
|
7
|
+
|
8
|
+
def driver
|
9
|
+
case
|
10
|
+
when String === @ws
|
11
|
+
if File.exists? @ws
|
12
|
+
return SOAP::WSDLDriverFactory.new(@ws).create_rpc_driver
|
13
|
+
end
|
14
|
+
when Array === @ws
|
15
|
+
return SimpleWS.get_driver(@ws[0], @ws[1])
|
16
|
+
when SOAP::WSDLDriverFactory === @ws
|
17
|
+
return @ws
|
18
|
+
end
|
19
|
+
|
20
|
+
raise "Do not know how to connect to driver"
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(name, host, ws, options = {})
|
24
|
+
@host = host
|
25
|
+
@name = name
|
26
|
+
@ws = ws
|
27
|
+
@smtp_host = options[:smtp_host] || 'localhost'
|
28
|
+
@smtp_port = options[:smtp_port] || 25
|
29
|
+
@sleep_time = options[:sleep_time] || 2
|
30
|
+
@jobs = {}
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_job(job_id, email)
|
34
|
+
@jobs[job_id] = email
|
35
|
+
end
|
36
|
+
|
37
|
+
def process
|
38
|
+
@jobs.each do |job_id, email|
|
39
|
+
if driver.done job_id
|
40
|
+
if driver.error job_id
|
41
|
+
error(job_id, email, driver.messages(job_id).last)
|
42
|
+
else
|
43
|
+
success(job_id, email)
|
44
|
+
end
|
45
|
+
@jobs.delete(job_id)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_mail(to, subject, body)
|
51
|
+
puts "Sending mail to #{ to }: #{ subject }"
|
52
|
+
message = RMail::Message.new
|
53
|
+
|
54
|
+
from = "noreply@" + @host.sub(/:.*/,'')
|
55
|
+
|
56
|
+
message.header['To'] = to
|
57
|
+
message.header['From'] = from
|
58
|
+
message.header['Subject'] = subject
|
59
|
+
|
60
|
+
main = RMail::Message.new
|
61
|
+
main.body = body
|
62
|
+
|
63
|
+
message.add_part(main)
|
64
|
+
|
65
|
+
Net::SMTP.start(@smtp_host.chomp, @smtp_port.to_i) do |smtp|
|
66
|
+
smtp.send_message message.to_s, from, to
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def error(job_id, email, msg)
|
72
|
+
body =<<-EOF
|
73
|
+
Dear #{ @name } user:
|
74
|
+
|
75
|
+
You job with id '#{ job_id }' has finished with error message:
|
76
|
+
|
77
|
+
#{ msg }
|
78
|
+
|
79
|
+
URL: http://#{@host.chomp}/#{ job_id }
|
80
|
+
|
81
|
+
Note: Do not reply to this message, it is automatically generated.
|
82
|
+
EOF
|
83
|
+
send_mail(email, "#{@name} [ERROR]: #{ job_id }", body)
|
84
|
+
end
|
85
|
+
|
86
|
+
def success(job_id, email)
|
87
|
+
body =<<-EOF
|
88
|
+
Dear #{ @name } user:
|
89
|
+
|
90
|
+
You job with id '#{ job_id }' has finished successfully:
|
91
|
+
|
92
|
+
URL: http://#{@host.chomp}/#{ job_id }
|
93
|
+
|
94
|
+
Note: Do not reply to this message, it is automatically generated.
|
95
|
+
EOF
|
96
|
+
send_mail(email, "#{@name} [SUCCESS]: #{ job_id }", body)
|
97
|
+
end
|
98
|
+
|
99
|
+
def pending?
|
100
|
+
! @jobs.empty?
|
101
|
+
end
|
102
|
+
|
103
|
+
def start
|
104
|
+
puts "Starting Email notifier."
|
105
|
+
puts "Name: #{ @name }"
|
106
|
+
puts "Host: #{ @host }"
|
107
|
+
puts "SMTP: #{ @smtp_host }"
|
108
|
+
@thread = Thread.new do
|
109
|
+
while true
|
110
|
+
begin
|
111
|
+
process
|
112
|
+
sleep @sleep_time
|
113
|
+
rescue
|
114
|
+
puts $!.message
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def stop
|
121
|
+
@thread.kill
|
122
|
+
end
|
123
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplews
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 10
|
8
|
+
- 0
|
9
|
+
version: 1.10.0
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Miguel Vazquez
|
@@ -9,39 +14,47 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-04-12 00:00:00 +02:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: soap4r
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 5
|
30
|
+
- 8
|
23
31
|
version: 1.5.8
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: rand
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
33
43
|
version: "0"
|
34
|
-
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
35
46
|
- !ruby/object:Gem::Dependency
|
36
47
|
name: builder
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
50
|
requirements:
|
41
51
|
- - ">="
|
42
52
|
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
43
55
|
version: "0"
|
44
|
-
|
56
|
+
type: :runtime
|
57
|
+
version_requirements: *id003
|
45
58
|
description: Generates WSDL automatically. It manages jobs as asynchronous processes
|
46
59
|
email: miguel.vazquez@fdi.ucm.es
|
47
60
|
executables:
|
@@ -56,6 +69,7 @@ files:
|
|
56
69
|
- lib/rake_pipeline.rb
|
57
70
|
- lib/simplews.rb
|
58
71
|
- lib/simplews/jobs.rb
|
72
|
+
- lib/simplews/notifier.rb
|
59
73
|
- lib/simplews/rake.rb
|
60
74
|
- LICENSE
|
61
75
|
- README.rdoc
|
@@ -72,18 +86,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
86
|
requirements:
|
73
87
|
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
75
91
|
version: "0"
|
76
|
-
version:
|
77
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
93
|
requirements:
|
79
94
|
- - ">="
|
80
95
|
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
81
98
|
version: "0"
|
82
|
-
version:
|
83
99
|
requirements: []
|
84
100
|
|
85
101
|
rubyforge_project:
|
86
|
-
rubygems_version: 1.3.
|
102
|
+
rubygems_version: 1.3.6
|
87
103
|
signing_key:
|
88
104
|
specification_version: 3
|
89
105
|
summary: Simplifies creating soap4r web services as stand-alone servers
|