Class: Taskr::Actions::Base

Inherits:
Object
  • Object
show all
Includes:
OpenWFE::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, Ruby, Shell, Taskr4rails

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parameters) ⇒ Base

Returns a new instance of Base.



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

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

Instance Method Details

#executeObject

Raises:

  • (NotImplementedError)


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

def execute
  raise NotImplementedError, "Implement me!"
end

#trigger(trigger_args = {}) ⇒ Object



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

def trigger(trigger_args = {})
  begin
    $LOG.info("Executing task #{self.task.name}")
    execute
    task.update_attribute(:last_triggered, Time.now)
    task.update_attribute(:last_triggered_error, nil)
  rescue => e
    puts
    $LOG.error(e)
    $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