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
15 def find_and_execute_task(path, hooks = {})
16   task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
17   result = nil
18   reporter = Capistrano::Datadog.reporter
19   task_name = task.fully_qualified_name
20   timing = Benchmark.measure(task_name) do
21     # Set the current task so that the logger knows which task to
22     # associate the logs with
23     reporter.current_task = task_name
24     trigger(hooks[:before], task) if hooks[:before]
25     result = execute_task(task)
26     trigger(hooks[:after], task) if hooks[:after]
27     reporter.current_task = nil
28   end
29 
30   # Record the task name, its timing and roles
31   roles = task.options[:roles]
32   if roles.is_a? Proc
33     roles = roles.call
34   end
35   reporter.record_task(task_name, timing.real, roles, task.namespace.variables[:stage], fetch(:application))
36 
37   # Return the original result
38   result
39 end