Class: Taskr::Actions::Base

Inherits:
Object
  • Object
show all
Includes:
Rufus::Schedulable
Defined in:
lib/taskr/actions.rb

Overview

The base class for all Actions. Extend this to define your own custom Action.

Direct Known Subclasses

Rest, RotateTaskLog, Ruby, Shell, Taskr4rails

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ Base

Returns a new instance of Base.



51
52
53
# File 'lib/taskr/actions.rb', line 51

def initialize(parameters)
  self.parameters = HashWithIndifferentAccess.new(parameters)
end

Instance Attribute Details

#parametersObject

Returns the value of attribute parameters.



47
48
49
# File 'lib/taskr/actions.rb', line 47

def parameters
  @parameters
end

#taskObject

Returns the value of attribute task.



48
49
50
# File 'lib/taskr/actions.rb', line 48

def task
  @task
end

#task_actionObject

Returns the value of attribute task_action.



49
50
51
# File 'lib/taskr/actions.rb', line 49

def task_action
  @task_action
end

Instance Method Details

#executeObject

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/taskr/actions.rb', line 55

def execute
  raise NotImplementedError, "Implement me!"
end

#to_sObject



77
78
79
# File 'lib/taskr/actions.rb', line 77

def to_s
  "#{self.class.name}(#{parameters.inspect})"
end

#trigger(trigger_args = {}) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/taskr/actions.rb', line 59

def trigger(trigger_args = {})
  begin
    $LOG.info("Executing task #{self.task.name.inspect}")
    execute
    task.update_attribute(:last_triggered, Time.now)
    task.update_attribute(:last_triggered_error, nil)
  rescue => e
    puts
    $LOG.error("Error while executing task #{self.task.name.inspect}! The error was: #{e}  (see Taskr log for debugging details)")
    $LOG.debug(e.backtrace.join($/))
    details = e.message
    details += "\n\n#{$LAST_ERROR_BODY}" if $LAST_ERROR_BODY # dumb way of reading Restr errors... Restr needs to be fixed
    task.update_attribute(:last_triggered, Time.now)
    task.update_attribute(:last_triggered_error, {:type => e.class.to_s, :message => details})
    raise e
  end
end