Class: Taskr::Actions::Base
- Inherits:
-
Object
- Object
- Taskr::Actions::Base
- 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
Instance Attribute Summary collapse
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#task ⇒ Object
Returns the value of attribute task.
-
#task_action ⇒ Object
Returns the value of attribute task_action.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(parameters) ⇒ Base
constructor
A new instance of Base.
- #to_s ⇒ Object
- #trigger(trigger_args = {}) ⇒ Object
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
#parameters ⇒ Object
Returns the value of attribute parameters.
47 48 49 |
# File 'lib/taskr/actions.rb', line 47 def parameters @parameters end |
#task ⇒ Object
Returns the value of attribute task.
48 49 50 |
# File 'lib/taskr/actions.rb', line 48 def task @task end |
#task_action ⇒ Object
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
#execute ⇒ Object
55 56 57 |
# File 'lib/taskr/actions.rb', line 55 def execute raise NotImplementedError, "Implement me!" end |
#to_s ⇒ Object
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. 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 |