如何将 JRuby Resque 进程部署为 war 文件?
我有一个 JRuby/Rails 应用程序,它部署为 WAR 文件并在 Tomcat 应用程序服务器中运行。我想使用delayed_job或Resque作为工具来完成长时间运行的作业,这些作业通过我的Rails应用程序使用的相同ActiveRecord子类来处理数据库。我希望它在不同的进程或线程中运行,以免使应用程序面向 Web 的一侧看起来很慢。
包含和使用delayed_job或Resque的说明非常清楚。例如,一旦我完成了使用 Resque 的所有 jiggery-pokery,我只需要做:
QUEUE=* jruby -J-cp /path/to/library -S rake environment resque:work
但这只能在命令行中工作。如何获取它以便我的 Resque 进程可以通过将 WAR 文件部署到 Tomcat 来运行?如果是,它是具有不同配置的同一个 WAR 文件还是不同的 WAR 文件?如果是不同的WAR文件,我该如何生成它?我是否需要第二个 Tomcat 来执行 Resque/DJ 流程?有没有办法将 Resque/DJ 进程放入自己的 JRuby/JVM 线程中?我是否必须进行任何配置才能实现此目的?
I have a JRuby/Rails application which is deployed as a WAR file and run in the Tomcat application server. I would like to use either delayed_job or Resque as a tool to do long-running jobs which schlep through the database through the same ActiveRecord subclasses use by my Rails application. And I want it to run in a different process or thread so as not to make my web-facing side of the application seem slow.
The instructions to include and use delayed_job or Resque are pretty clear. For example, once I have done all of the jiggery-pokery to use Resque, I simply have to do:
QUEUE=* jruby -J-cp /path/to/library -S rake environment resque:work
But this only works from the command line. How do I get it so that my Resque process(es) can run by deploying a WAR file to Tomcat? If so, is it the same WAR file with a different configuration or a different WAR file? If it is a different WAR file, how do I generate it? Do I need a second Tomcat for the Resque/DJ process? Is there a way to put the Resque/DJ process into its own JRuby/JVM thread? Is there any configuration jiggery-pokery I must do to get this going?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JRuby 确实可以识别
ARGV[0] =~ /ruby$/
的 shell 命令并在进程中运行它们,因此您可以利用它来发挥自己的优势。假设您将Rakefile
包含在您的 war 文件中,您可以启动一个线程并使用应用程序初始值设定项中的类似命令在其中启动 Resque。如果您使用 Bundler,它已经设置了环境,并且应该将其传递给进程内子 JRuby。JRuby does recognize shell commands whose
ARGV[0] =~ /ruby$/
and run them in-process, so you could use this to your advantage. Assuming you include yourRakefile
in your war file, you could start a thread and launch Resque in it with a similar command from an application initializer. If you're using Bundler, it will already have the environment set up and it should be passed to the in-process child JRuby.