您建议采用什么方法来实现基于 Web 的调度程序

发布于 2024-07-27 04:17:39 字数 317 浏览 5 评论 0原文

我发现我经常必须在我开发的应用程序中实现某种调度程序。 应用范围可以从简单的维护任务到相当复杂的任务。

到目前为止,我的方法是设置 cron 作业,本质上是对排队命令进行批处理。 例如,我让 cron 每 5 分钟调用一个脚本(我在 RubyOnRails 中工作,所以这是一个运行程序脚本),它检查是否有任何需要处理的项目,然后将任务委托给适当的处理程序。

这可行,但由于某种原因感觉不是最好的方法。 你能推荐一些东西,或者对此有什么评论吗?

我在 Ruby on Rails 工作,但这个讨论没有理由仅限于 RoR。

谢谢,

I have found that I often have to implement some sort of a scheduler in the applications I develop. The applications can range from simple maintenance tasks to fairly complex.

So far my approach has been to set up cron jobs that essentially do batch processing of queued commands. For example, I have cron invoking a script (I am working in RubyOnRails so this is a runner script) every 5 minutes, which checks if there are any items that need to be processed, then delegates the tasks to appropriate handlers.

This works, but for some reason doesn't feel like the best approach. Can you recommend something, or have any comments on this?

I working in Ruby on Rails, but there is no reason this discussion should be limited only to RoR.

Thanks,

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

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

发布评论

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

评论(3

提笔落墨 2024-08-03 04:17:39

有多种方法可以做到这一点。 在我们最近开发的一个项目中,我们使用了 delayed_job,这是一款出色的 Rails 异步工作工具。 我们可以将一个作业设置为每 5 分钟运行一次,然后该作业完成后会创建另一个作业,依此类推。

其他工具(例如 BackgroundRB)实际上默认支持 cron 风格的工作程序。

我经常发现,每分钟执行一次 rake 任务来将新作业添加到elasted_job 效果非常好; 你可能想尝试一下。 它是最具弹性的,可以让您将所有计时器逻辑保留在 Ruby 中,同时不需要丑陋的 hack 或可能会破坏的设置,如我最初的elasto_job 示例(例如,您必须清除工作队列;您现在必须再次重置所有作业才能获得它们)好好工作)。

Delayed_job 非常容易使用并且非常容易破解,所以如果您正在寻找一个开始的地方,那么这可能是一个不错的地方。

A number of ways to do this. For one project we recently developed we used delayed_job, an excellent async worker tool for Rails. We can set a job up to run every 5 minutes, and the job then creates another job once it's done, and so on.

Other tools like BackgroundRB actually support a cron-style worker by default.

I often find that doing a once-per-minute rake task to add new jobs to delayed_job works really well; you might want to try that. It's the most resilient and lets you keep all the timer logic in Ruby while not requiring ugly hacks or potentially breakable setups like my initial delayed_job example (eg you have to purge the work queue; you now have to reset all your jobs again to get them working properly).

Delayed_job is extremely easy to work on and very hackable, so if you're looking for somewhere to start that's probably as good a place as any.

送君千里 2024-08-03 04:17:39

另一个建议是创建您自己的自定义守护程序。 这将使您能够灵活地完成几乎所有您需要的事情。

精彩的 Railscast 截屏视频对此进行了介绍 - http://railscasts.com/episodes/129-custom -守护进程

Another suggestion is to create your own custom daemon. This will give you the flexibility to do pretty much anything you need.

It was covered in a excellent Railscast screencast - http://railscasts.com/episodes/129-custom-daemon

妄断弥空 2024-08-03 04:17:39

不明白为什么你不使用 cron 和 script/runner。 好处是您不必始终加载(额外需要的)Rails 环境,仅在需要运行作业时才加载。

缺点是它取决于 cron 是否存在......?

Can't see why you wouldn't use cron and script/runner. The benefit is that you don't have your (additionally required) Rails environment always loaded, only loaded when you need to run the job.

Downside is that it depends on cron being present ...?

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