Permalink
Browse files

Add persistance

  • Loading branch information...
1 parent 2c1d468 commit cdb0521c014333257382871bebc08bd1b60872a7 @mikisvaz committed Apr 16, 2010
Showing with 17 additions and 6 deletions.
  1. +1 −1 .vimproject
  2. +14 −2 lib/simplews/notifier.rb
  3. +2 −3 test/simplews/test_notifier.rb
View
@@ -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
@@ -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
@@ -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

0 comments on commit cdb0521

Please sign in to comment.