27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/rails/hyperdrive/console_executor.rb', line 27
def eval(code, timeout: DEFAULT_TIMEOUT_SECONDS)
original_stdout = $stdout
original_stderr = $stderr
captured_out = StringIO.new
captured_err = StringIO.new
$stdout = captured_out
$stderr = captured_err
started_at = monotonic_now
result = nil
exception = nil
begin
::Timeout.timeout(timeout.to_f) do
result = TOPLEVEL_BINDING.eval(code, "(hyperdrive run_ruby)", 1)
end
rescue Exception => e exception = e
end
Result.new(
result: result,
stdout: captured_out.string,
stderr: captured_err.string,
elapsed_ms: ((monotonic_now - started_at) * 1000).round,
exception: exception
)
ensure
$stdout = original_stdout
$stderr = original_stderr
end
|