Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add persistance

  • Loading branch information...
commit cdb0521c014333257382871bebc08bd1b60872a7 1 parent 2c1d468
@mikisvaz authored
View
2  .vimproject
@@ -10,8 +10,8 @@ SimpleWS=/$PWD filter="*.rb Rakefile *.sh *.rake *.txt" {
rake_pipeline.rb
simplews=simplews {
jobs.rb
+ notifier.rb
rake.rb
- monitor.rb
}
}
test=test {
View
16 lib/simplews/notifier.rb
@@ -27,11 +27,23 @@ def initialize(name, host, ws, options = {})
@smtp_host = options[:smtp_host] || 'localhost'
@smtp_port = options[:smtp_port] || 25
@sleep_time = options[:sleep_time] || 2
- @jobs = {}
+ @filename = options[:filename]
+
+ if @filename && File.exists?(@filename)
+ @jobs = Marshal.load(File.open(@filename))
+ else
+ @jobs = {}
+ end
end
def add_job(job_id, email)
@jobs[job_id] = email
+ File.open(@filename, 'w') do |f| f.write Marshal.dump(@jobs) end if @filename
+ end
+
+ def delete_job(job_id)
+ @jobs.delete(job_id)
+ File.open(@filename, 'w') do |f| f.write Marshal.dump(@jobs) end if @filename
end
def process
@@ -42,7 +54,7 @@ def process
else
success(job_id, email)
end
- @jobs.delete(job_id)
+ delete_job(job_id)
end
end
end
View
5 test/simplews/test_notifier.rb
@@ -3,8 +3,7 @@
require 'simplews/notifier'
require 'soap/wsdlDriver'
-MAIL="mikisvaz@gmail.com"
-#MAIL="change.to@your.mail.com"
+MAIL="change.to@your.mail.com"
WSDL_FILE='TestMonitor_Simplews.wsdl'
@@ -23,7 +22,7 @@ class TestMonitor < Test::Unit::TestCase
@@server.wsdl WSDL_FILE
- @@monitor = SimpleWS::Jobs::Notifier.new("Test", "localhost:1984", WSDL_FILE, :smtp_host => 'ucsmtp.ucm.es')
+ @@monitor = SimpleWS::Jobs::Notifier.new("Test", "localhost:1984", WSDL_FILE, :smtp_host => 'ucsmtp.ucm.es', :filename => '/tmp/monitor.marshal')
@@driver = SOAP::WSDLDriverFactory.new(WSDL_FILE).create_rpc_driver
Please sign in to comment.
Something went wrong with that request. Please try again.