在 DelayedJob 中存储未评估的 ActiveRecord 查询
我想安排一个延迟作业,其中包含活动记录查询(或条件),该查询将在作业实际运行时进行评估。
前任。我有一个自定义作业,正在生成并向用户发送通知。 我想将参数/查询/条件发送到作业,以过滤通知发送到的用户。
我可以评估一个字符串,但这看起来很丑陋。
该项目使用的是 Rails 2.3.5,所以我不能走 Arel 路线。
我看到了有关 Ambition 的内容,但自 2008 年以来就没有看到过,所以我不确定该项目的状态。
建议?
I'd like to schedule a delayed job that contains an active record query (or conditions) that will be evaluated when the job is actually run.
Ex. I have a custom Job that is generating and sending notifications to users.
I want to send parameters/query/conditions to the job that would filter the users that notifications get sent to.
I could eval a string but that seems so ugly.
The project is using Rails 2.3.5 so I can't go the Arel route.
I see stuff about Ambition but nothing since 2008 so I'm not sure the status of the project.
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在创建作业时将条件等作为散列发送到作业,然后像通常使用 ActiveRecord 一样使用它。也许是这样的:
然后你像这样创建作业:
如果这不适合你,那么也许你可以提供你当前的代码。
You could send the conditions etc as a hash to the job when you create it and then use it just like you normally do with ActiveRecord. Perhaps something like this:
And then you create the Job like this:
If this is not working for you, then perhaps you can supply your current code.