From a6853706178388422e725f07f2bb0445fdeb7bd6 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Sat, 24 Nov 2012 14:58:59 +0000 Subject: Use the factory-method to instantiate an alerting method. --- lib/custodian/worker.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'lib/custodian') 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. @@ -40,6 +40,12 @@ module Custodian attr_reader :queue + # + # The name of the alerter to use. + # + attr_reader :alerter + + # # How many times we re-test before we detect a failure # @@ -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 -- cgit v1.2.1