[Proposal] Provide API to wrap `runner` command's execution

Hello, I’m the maintainer of the sentry-ruby gem. I’ve got a request for capturing exceptions from the runner command execution. I think it’s reasonable since many developers use it to run scripts or long-running methods on production.

But when trying to implement it, I found that there seems to be no way to wrap a method around the command execution. This is a bummer because I also found the same need in other SDKs:

It’s interesting to see that Airbrake implemented it using the at_exit block. But it still feels like a workaround to me.

And in addition to exception capturing, having a block to wrap around the runner execution can also allow us to measure and report the executed script’s performance.

Possible Interfaces

runner do
  # setup for runner
end

# more aligned with the current interfaces
around_runner do |runner_execution|
  runner_execution.call
rescue => e
  report_exception(e)
end

# or this

def around_runner(block)
  block.call
rescue => e
  report_exception(e)
end

(I only focus on the runner command because I don’t think other command have a similar need for exception capturing and/or performance measuring).

2 Likes