lib/taskr/actions.rb in taskr-0.3.0 vs lib/taskr/actions.rb in taskr-0.4.0
- old
+ new
@@ -56,17 +56,17 @@
raise NotImplementedError, "Implement me!"
end
def trigger(trigger_args = {})
begin
- $LOG.info("Executing task #{self.task.name}")
+ $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(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.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})
@@ -93,20 +93,20 @@
self.actions = []
end
def trigger(trigger_args = {})
begin
- $LOG.info("Executing task #{self.task.name}")
+ $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(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.message}"})
# 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.message}\n#{e.backtrace}")
@@ -266,12 +266,16 @@
params2[key] = value
end
parameters['params'] = params2
end
- Restr.logger = LogEntry.logger_for_action(task_action)
- Restr.do(parameters['method'], parameters['url'], (parameters['params'] unless parameters['params'].blank?), auth)
+ options = {:logger => LogEntry.logger_for_action(task_action)}
+ options.merge!(auth) if auth
+ Restr.do(parameters['method'],
+ parameters['url'],
+ (parameters['params'] unless parameters['params'].blank?),
+ options)
end
end
class Howlr < Rest
self.parameters = ['url', 'from', 'recipients', 'subject', 'body', 'username', 'password', 'content_type']
@@ -294,22 +298,24 @@
super
end
end
class Taskr4rails < Base
- self.parameters = ['url', 'auth', 'ruby_code']#, 'shell_command']
+ self.parameters = ['url', 'auth', 'ruby_code', 'dont_wait']#, 'shell_command']
self.description = "Executes code on a remote Rails server via the taskr4rails plugin."
def execute
data = {
+ :task_name => task.name,
+ :task_id => task.id,
:auth => parameters['auth'],
+ :dont_wait => parameters['dont_wait'],
:ruby_code => parameters['ruby_code']#,
#:shell_command => parameters['shell_command']
}
-
-
- Restr.logger = LogEntry.logger_for_action(task_action)
- Restr.post(parameters['url'], data)
+
+ options = {:logger => LogEntry.logger_for_action(task_action)}
+ Restr.post(parameters['url'], data, options)
end
end
end
end
\ No newline at end of file