滑轨的关闭钩 [英] Shutdown hook for Rails

查看:51
本文介绍了滑轨的关闭钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Rails关闭时运行一些清理代码-可能吗?我的情况是,我在后台有一些线程(我正在使用jruby并调用java)在整个进程的生命周期中都存在,我需要让他们知道关闭自己的线程

I'd like to have some cleanup code run when Rails is shutting down - is that possible? My situation is that I have a few threads in the background (I'm using jruby and calling into java) that live for the life of the process and I need to let them know to shut themselves down

谢谢!

推荐答案

可能应该只使用Ruby退出处理程序,这是一个内核方法:

Probably should just use the Ruby exit handler, which is a Kernel method:

$ irb
>> at_exit do
?>   puts 'bye...'
>> end
=> #<Proc:0xb79a87e4@(irb):1>
>> exit
bye...
$ 

这篇关于滑轨的关闭钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆