Class: EY::Serverside::Callbacks::Executor::Ruby::Executor
- Inherits:
-
Base
- Object
- Base
- EY::Serverside::Callbacks::Executor::Ruby::Executor
show all
- Defined in:
- lib/engineyard-serverside/callbacks/executor/ruby/executor.rb
Overview
An executor for Ruby hooks
Instance Attribute Summary
Attributes inherited from Base
#config, #hook, #shell
Instance Method Summary
collapse
Methods inherited from Base
execute, #execute, #hook_path, #initialize, #paths
Methods included from Railway
#call, included
#Failure, #Success
Instance Method Details
#announce_execution(input = {}) ⇒ Object
57
58
59
60
|
# File 'lib/engineyard-serverside/callbacks/executor/ruby/executor.rb', line 57
def announce_execution(input = {})
shell.info "Executing #{hook.path} ..."
Success(input)
end
|
#context_eval(input = {}) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/engineyard-serverside/callbacks/executor/ruby/executor.rb', line 62
def context_eval(input = {})
Dir.chdir(paths.active_release.to_s) do
begin
Context.new(config, shell, hook).instance_eval(input[:code])
rescue Exception => exception
return Failure(
input.merge(
{
:reason => :execution_failed,
:exception => exception
}
)
)
end
end
Success(input)
end
|
#display_deprecation_warnings(input = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/engineyard-serverside/callbacks/executor/ruby/executor.rb', line 43
def display_deprecation_warnings(input = {})
code = input[:code]
if code =~ /@configuration/
shell.warning("Use of `@configuration` in deploy hooks is deprecated.\nPlease use `config`, which provides access to the same object.\n\tin #{hook_path}")
end
if code =~ /@node/
shell.warning("Use of `@node` in deploy hooks is deprecated.\nPlease use `config.node`, which provides access to the same object.\n\tin #{hook_path}")
end
Success(input)
end
|
#display_hook_error(exception) ⇒ Object
102
103
104
105
106
107
108
109
110
|
# File 'lib/engineyard-serverside/callbacks/executor/ruby/executor.rb', line 102
def display_hook_error(exception)
shell.fatal <<-ERROR
Exception raised in hook #{hook_path}.
#{exception.class}: #{exception.to_s}
Please fix this error before retrying.
ERROR
end
|
#handle_failure(payload = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/engineyard-serverside/callbacks/executor/ruby/executor.rb', line 19
def handle_failure(payload = {})
case payload[:reason]
when :execution_failed
exception = payload[:exception]
display_hook_error(exception)
raise exception
when :syntax_error
abort "*** [Error] Invalid Ruby syntax in hook: #{hook_path} ***\n*** #{payload[:syntax_error]} ***"
else
abort "*** [Error] An unknown error occurred for hook: #{hook_path} ***"
end
end
|
#ruby_bin ⇒ Object
97
98
99
100
|
# File 'lib/engineyard-serverside/callbacks/executor/ruby/executor.rb', line 97
def ruby_bin
File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
end
|
#validate_hook(input = {}) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/engineyard-serverside/callbacks/executor/ruby/executor.rb', line 81
def validate_hook(input = {})
output = `#{ruby_bin} -c #{hook_path} 2>&1`
unless output =~ /Syntax OK/
return Failure(
input.merge(
{
:reason => :syntax_error,
:syntax_error => output
}
)
)
end
Success(input.merge({:code => hook.read}))
end
|