Rails 延迟作业 访问后台作业的值
在我的 Rails 应用程序中,我有一个计时器每秒计时,根据不同的对象更改其状态。因此,我决定使用 Observer 来实现这一点。然而,当我运行观察者时,我注意到它挂起了我的整个应用程序,直到计时器完成。因此,我正在考虑使用delayed_job将计时器保留为后台作业。
现在我的问题是有没有办法每秒获取计时器的值并将其用于控制器中的某些操作?例如,如果我有一组在不同时间出现的图像,我理想地希望从计时器中获取当前时间,如果图像的时间与当前时间匹配,则图像会发生变化。那么,是否可以每秒从后台进程获取这样的值?如果是,有人可以详细说明吗?
In my rails app, i have a timer ticking every second based on which different objects change their state. Thus, i decided to use Observer for this. However, when i ran the observer, i noticed it hung up my entire app until the timer completed. Thus, i was thinking of keeping the timer as a background job using delayed_job.
Now my query is that is there any way to fetch the value of the timer every second and use it for some operations in the controller? Example, if i had a set of images appearing at different times, i would ideally like to fetch this current time from the timer and if timing of the image and the current time matches, the images change. Hence, is it possible to fetch the value like this every second from the background process? If yes, can anyone please elaborate?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需让您的延迟作业后台进程将计时器值和相应的图像链接保存到表中即可。然后在控制器中读取该值并采取相应的操作。
Just make your delayed job background process save the timer value and corresponding image link to a table. Then read in that value in your controller and act accordingly.