Class: Taskr::Actions::Multi
- Inherits:
-
Object
- Object
- Taskr::Actions::Multi
- Includes:
- Rufus::Schedulable
- Defined in:
- lib/taskr/actions.rb
Overview
Do not extend this class. It is used internally to schedule multiple actions per task.
If you want to define your own custom Action, extend Taskr::Actions::Base
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#task ⇒ Object
Returns the value of attribute task.
Instance Method Summary collapse
-
#initialize ⇒ Multi
constructor
A new instance of Multi.
- #trigger(trigger_args = {}) ⇒ Object
Constructor Details
#initialize ⇒ Multi
Returns a new instance of Multi.
92 93 94 |
# File 'lib/taskr/actions.rb', line 92 def initialize self.actions = [] end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
89 90 91 |
# File 'lib/taskr/actions.rb', line 89 def actions @actions end |
#task ⇒ Object
Returns the value of attribute task.
90 91 92 |
# File 'lib/taskr/actions.rb', line 90 def task @task end |
Instance Method Details
#trigger(trigger_args = {}) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/taskr/actions.rb', line 96 def trigger(trigger_args = {}) begin $LOG.info("Executing task #{self.task.name.inspect}") actions.each do |a| a.execute LogEntry.info(a, "Action #{a} executed.") end # TODO: maybe we should store last_triggered time on a per-action basis? task.update_attribute(:last_triggered, Time.now) task.update_attribute(:last_triggered_error, nil) rescue => e $LOG.error("Error while executing task #{self.task.name.inspect}! The error was: #{e} (see Taskr log for debugging details)") $LOG.debug("#{e.backtrace}") task.update_attribute(:last_triggered, Time.now) task.update_attribute(:last_triggered_error, {:type => e.class.to_s, :details => "#{e.}"}) # FIXME: Maybe actions should be responseible for logging their errors, otherwise we double-log the same error. LogEntry.error(task, "Task #{task} raised an exception: \n#{e.class}: #{e.}\n#{e.backtrace}") raise e end end |