diff options
author | Steve Kemp <steve@steve.org.uk> | 2012-11-24 14:58:59 +0000 |
---|---|---|
committer | Steve Kemp <steve@steve.org.uk> | 2012-11-24 14:58:59 +0000 |
commit | a6853706178388422e725f07f2bb0445fdeb7bd6 (patch) | |
tree | 96374697dddf7b009ce00b5183acf17d1d029d36 | |
parent | ea62bc30350a74c8213980d3415db9d9c2d185ef (diff) |
Use the factory-method to instantiate an alerting method.
-rw-r--r-- | lib/custodian/worker.rb | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/custodian/worker.rb b/lib/custodian/worker.rb index 221576e..763805f 100644 --- a/lib/custodian/worker.rb +++ b/lib/custodian/worker.rb @@ -11,7 +11,7 @@ require 'logger' # # Our modules. # -require 'custodian/alerter.rb' +require 'custodian/alerts' # # This list of all our protocol tests. @@ -41,6 +41,12 @@ module Custodian # + # The name of the alerter to use. + # + attr_reader :alerter + + + # # How many times we re-test before we detect a failure # attr_reader :retry_count @@ -57,11 +63,14 @@ module Custodian # # Constructor: Connect to the queue # - def initialize( server, logfile ) + def initialize( server, alerter, logfile ) # Connect to the queue @queue = Beanstalk::Pool.new([server]) + # Get the alerter-type to instantiate + @alerter = alerter + # Instantiate the logger. @logger = Logger.new( logfile, "daily" ) @@ -144,12 +153,12 @@ module Custodian # - # As a result of this test we'll either raise/clear with mauve. + # As a result of this test we'll either raise/clear with one + # of our alerter classes. # - # This helper will do that job. + # Here we create one of the correct type. # - alert = Custodian::Alerter.new( test ) - + alert = Custodian::AlertFactory.create( @alerter, test ) # # We'll run no more than MAX times. @@ -183,7 +192,7 @@ module Custodian # Raise the alert, passing the error message. # log_message( "Test failed - alerting with #{test.error()}" ) - alert.raise( test.error() ) + alert.raise() end rescue => ex |