BackgroundJobs 完成后停止作业

发布于 2024-10-10 17:39:50 字数 1059 浏览 9 评论 0原文

我过去使用过Delayed_job。我有一个在服务器上运行的旧项目,我无法从 Ruby 1.8.6 升级到 1.8.7,因此无法使用延迟作业,所以我正在尝试 BackgroundJobs http://codeforpeople.rubyforge.org/svn/bj/trunk/README

我让它工作,以便我的工作运行,但有些事情似乎不太对劲。例如,如果我像这样运行作业:

jobs = Bj.submit "echo hi", :is_restartable => false, :limit => 1, :forever => false

然后我会在 bj_job 表中看到该作业,并且在标准输出中看到它与“hi”一起完成。我还看到表中只有一项作业,并且它不会继续重新运行它。

出于某种原因,如果我这样做:

jobs = Bj.submit "./script/runner ./jobs/calculate_mean_values.rb #{self.id}", :is_restartable => false, :limit => 1, :forever => false

作业仍然按预期完成,但是,它不断在 bj_job 表中插入新行,并且该方法会一遍又一遍地运行,直到我停止我的开发服务器。这是它应该如何工作的吗?

我正在使用 Ruby 1.8.6 和 Rails 2.1.2,但没有升级选项。我正在使用 Bj 的插件风格。

因为我只需要在模型保存后运行一次该过程,所以我可以直接使用脚本/运行程序来使其工作,如下所示:

system " RAILS_ENV=#{RAILS_ENV}   ruby  #{RAILS_ROOT}/script/runner   'CompositeGrid.calculate_values(#{self.id})'  & "

但想知道我在后台作业中是否做错了什么,

I've used Delayed_job in the past. I have an old project that runs on a server where I can't upgrade from Ruby 1.8.6 to 1.8.7, and therefore can't use Delayed Job, so I'm trying BackgroundJobs http://codeforpeople.rubyforge.org/svn/bj/trunk/README

I have it working so that my job runs, but something doesn't seem right. For example, if I run the job like this:

jobs = Bj.submit "echo hi", :is_restartable => false, :limit => 1, :forever => false

Then I see the job in the bj_job table and I see that it completed along with 'hi' in stdout. I also see only one job in the table and it doesn't keep re-running it.

For some reason if I do this:

jobs = Bj.submit "./script/runner ./jobs/calculate_mean_values.rb #{self.id}", :is_restartable => false, :limit => 1, :forever => false

The job still completes as expected, however, it keeps inserting new rows in the bj_job table, and the method gets run over and over until I stop my dev server. Is that how it is supposed to work?

I'm using Ruby 1.8.6 and Rails 2.1.2 and I don't have the option of upgrading. I'm using the plugin flavor of Bj.

Because I just need to run the process once after the model is saved, I have it working by using script/runner directly like this:

system " RAILS_ENV=#{RAILS_ENV}   ruby  #{RAILS_ROOT}/script/runner   'CompositeGrid.calculate_values(#{self.id})'  & "

But would like to know if I'm doing something wrong with Background Jobs,

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

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

发布评论

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

评论(1

意中人 2024-10-17 17:39:50

好吧,这是愚蠢的用户错误。事实证明,我收到了一个回调,该回调正在重新启动进程并创建无限循环。修复回调后,它完全按预期工作。

OK, this was stupid user error. As it turns out, I had a call back that was restarting the process and creating an endless loop. After fixing the call back it is working exactly as expected.

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