class Loadrunner::Runner
Executes event hooks
Attributes
hooks_dir[RW]
opts[R]
response[RW]
Public Class Methods
new(opts)
click to toggle source
# File lib/loadrunner/runner.rb, line 8 def initialize(opts) @hooks_dir = 'hooks' @opts = opts end
Public Instance Methods
execute()
click to toggle source
Execute all matching hooks based on the input payload. This method populates the `#response` object, and returns true on success.
# File lib/loadrunner/runner.rb, line 15 def execute set_environment_vars @response = opts.dup hooks = locate_hooks @response[:matching_hooks] = matching_hooks if hooks.empty? @response[:error] = "Could not find any hook to process this request. Please implement one of the 'matching_hooks'." return false else execute_all hooks @response[:executed_hooks] = hooks return true end end
Private Instance Methods
execute_all(hooks)
click to toggle source
Execute all hooks.
# File lib/loadrunner/runner.rb, line 46 def execute_all(hooks) hooks.each do |hook| run_bg hook end end
locate_hooks()
click to toggle source
Find all hooks that fit the payload meta data.
# File lib/loadrunner/runner.rb, line 35 def locate_hooks hooks = [] matching_hooks.each do |hook| hooks << hook if File.exist? hook end hooks end
matching_hooks()
click to toggle source
# File lib/loadrunner/runner.rb, line 64 def matching_hooks base = "#{hooks_dir}/#{opts[:repo]}/#{opts[:event]}" hooks = [ "#{hooks_dir}/global", "#{hooks_dir}/#{opts[:repo]}/global", "#{base}" ] hooks << "#{base}@branch=#{opts[:branch]}" if opts[:branch] if opts[:tag] hooks << "#{base}@tag=#{opts[:tag]}" hooks << "#{base}@tag" end hooks end
run_bg(cmd)
click to toggle source
Run a command in the background.
# File lib/loadrunner/runner.rb, line 53 def run_bg(cmd) job = fork { exec cmd } Process.detach job end
set_environment_vars()
click to toggle source
Set all payload meta data as environment variables so that the hook can use them.
# File lib/loadrunner/runner.rb, line 60 def set_environment_vars opts.each { |key, value| ENV["LOADRUNNER_#{key.to_s.upcase}"] = value } end