停止守护进程会损坏我的数据吗?

发布于 2024-10-08 04:01:56 字数 128 浏览 5 评论 0原文

我正在使用delayed_job在我的rails应用程序上运行一些后台进程。这些进程读取和写入数据库以及写入日志文件。

我的问题是 - 当我停止作业时,它是否会终止进程(这可能最终会损坏我的数据)还是等待作业结束或类似的事情?

I'm using delayed_job to run some background processes on my rails app. These processes read and write to the DB as well as writing to a log file.

My question is - when I stop the jobs, does it kill the process (which can end up corrupting my data) or does it wait for the job to end or something like that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别挽留 2024-10-15 04:01:56

这一切都取决于您如何编写代码。

通常,终止一个作业会猛烈地插入代码并立即停止。这可能是在写入过程中或在刷新缓冲区或正常关闭文件之前。

如果您有必须完成的任务,您可以捕获信号。然后,您的代码可以选择忽略该信号并继续运行,这不是最佳解决方案,或者它可以开始正常关闭、刷新缓冲区、关闭数据库连接、关闭文件等,然后退出。

而且,忽略信号不好的原因是操作系统发送一些信号来告诉应用程序在系统关闭或重新启动之前关闭。不关闭的应用程序可能会让用户或系统管理员生气,然后他们会找到一种方法让它退出,很可能是以一种不礼貌的方式。

查看 Signal 了解更多信息。

That all depends on how you wrote your code.

Generally killing a job jerks the plug on your code and it immediately stops. That could be in the middle of a write or before a buffer gets flushed or a file is gracefully closed.

If you have tasks that HAVE to complete you can trap signals. Your code can then choose to ignore the signal and continue running, which isn't an optimal solution, or it could begin shutting down gracefully, flushing buffers, closing DB connections, closing files, etc., followed by quitting.

And, the reason ignoring an signal isn't good is some are sent by the OS to tell apps to shutdown prior to the system shutting down or restarting. Apps that don't close down can get the user or sysadmin pissed, who will then find a way to MAKE it quit, most likely in an ungraceful way.

Check out Signal for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文