Rails:我可以在其他服务器上运行后台作业吗? [英] Rails: Can I run backgrounds jobs in a different server?

查看:73
本文介绍了Rails:我可以在其他服务器上运行后台作业吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在一个服务器上托管应用程序,并在另一台服务器上排队作业?

Is it possible to host the application in one server and queue jobs in another server?

可能的示例:


  1. 两个不同的EC2实例,一个使用主服务器,第二个使用排队服务。

  1. Two different EC2 instances, one with the main server and the second with the queueing service.

主机

可以在Heroku中使用该应用并使用EC2实例吗?

Is that possible?

谢谢

推荐答案

是的,当然可以。

要使其正常工作,需要设置一些延迟时间。

There are a couple of requirements for it to work:


  1. 服务器必须已同步时钟。只要服务器时区都设置​​为相同,通常就没有问题。

  2. 服务器都必须访问相同的数据库。

要做到这一点,您只需在两个(或所有,如果有两个以上)服务器上都具有相同的应用程序,然后在要处理作业的任何服务器上启动工作程序即可。任何一台服务器都仍可以将作业排队,但是只有运行工人的作业才能真正处理它们。

To do it, you simply have the same application on both (or all, if more than two) servers, and start workers on whichever server you want to process jobs. Either server can still queue jobs, but only the one(s) with workers running will actually process them.

例如,我们有一个接口服务器, db 服务器和几个 worker 服务器。 接口服务器通过Apache / Passenger为应用程序提供服务,将Rails应用程序连接到 db 服务器。 workers 具有相同的应用程序,尽管Apache没有运行,并且您无法通过http访问该应用程序。另一方面,他们的确有延迟工作的工人在跑。在常见情况下,接口服务器在 db worker中将作业排队服务器处理它们。

For example, we have one interface server, a db server and several worker servers. The interface server serves the application via Apache/Passenger, connecting the Rails application to the db server. The workers have the same application, though Apache isn't running and you can't access the application through http. They do, on the other hand, have delayed_jobs workers running. In a common scenario, the interface server queues up jobs in the db, and the worker servers process them.

一个警告:如果您依赖应用程序中的物理文件(附件,日志文件,下载的XML)或其他任何东西),您很可能需要像S3这样的解决方案来保留这些文件。这样做的原因是各个服务器可能没有实际的文件。例如,如果您的用户要将自己的个人资料图片上传到面向Web的服务器上,则文件很可能存储在该服务器上。如果您随后还有其他服务器来调整个人资料图片的大小,则该图片将不在辅助服务器上存在。

One word of caution: If you're relying on physical files in your application (attachments, log files, downloaded XML or anything else), you'll most likely need a solution like S3 to keep those files. The reason for this is that the individual servers might not have the actual files. An example of this is if your user were to upload their profile picture on your web-facing server, the files would likely be stored on that server. If you then have another server to resize the profile pictures, the image wouldn't exist on the worker server.

这篇关于Rails:我可以在其他服务器上运行后台作业吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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