module Capistrano::Configuration::Execution

Public Instance Methods

find_and_execute_task(path, hooks = {}) click to toggle source

Attempts to locate the task at the given fully-qualified path, and execute it. If no such task exists, a Capistrano::NoSuchTaskError will be raised. Also, capture the time the task took to execute, and the logs it outputted for submission to Datadog

# File lib/capistrano/datadog/v2.rb, line 15
def find_and_execute_task(path, hooks = {})
  task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
  result = nil
  reporter = Capistrano::Datadog.reporter
  task_name = task.fully_qualified_name
  timing = Benchmark.measure(task_name) do
    # Set the current task so that the logger knows which task to
    # associate the logs with
    reporter.current_task = task_name
    trigger(hooks[:before], task) if hooks[:before]
    result = execute_task(task)
    trigger(hooks[:after], task) if hooks[:after]
    reporter.current_task = nil
  end

  # Record the task name, its timing and roles
  roles = task.options[:roles]
  if roles.is_a? Proc
    roles = roles.call
  end
  reporter.record_task(task_name, timing.real, roles, task.namespace.variables[:stage], fetch(:application))

  # Return the original result
  result
end