class Procrastinator::LoggedTask

Task wrapper that adds logging to each step.

@author Robin Miller

@see Task

Attributes

logger[R]

Public Class Methods

new(task, logger: Logger.new(StringIO.new)) click to toggle source
Calls superclass method
# File lib/procrastinator/logged_task.rb, line 21
def initialize(task, logger: Logger.new(StringIO.new))
   super task
   @logger = logger || raise(ArgumentError, 'Logger cannot be nil')
end

Public Instance Methods

fail(error) click to toggle source

@param (see Task#fail)

# File lib/procrastinator/logged_task.rb, line 38
def fail(error)
   hook = task.fail(error)
   begin
      @logger.error("Task #{ hook }ed: #{ task }")
   rescue StandardError => e
      warn "Task logging error: #{ e.message }"
   end
   hook
end
run() click to toggle source

(see Task#run)

# File lib/procrastinator/logged_task.rb, line 27
def run
   task.run

   begin
      @logger.info("Task completed: #{ task }")
   rescue StandardError => e
      warn "Task logging error: #{ e.message }"
   end
end