[英]A cron job that creates objects - rails
I am working on an event app, that showcases the events near my area. 我正在开发一个活动应用程序,该应用程序展示了我所在区域附近的活动。
A Boolean is_weekly_event
is set for each entry. 为每个条目设置一个布尔值
is_weekly_event
。
If it is set to true I need to show that event in my app every week on the same data and time. 如果将其设置为true,则需要每周在我的应用程序中以相同的数据和时间显示该事件。
Therefore, I need to write a cron job, that re-creates this event every time it passes it's end_time, for the same time next week! 因此,我需要编写一个cron作业,每当它经过end_time时就在下周的同一时间重新创建此事件!
Thanks in advance! 提前致谢!
you can use whenever gem to add cron job. 您可以随时使用gem添加cron作业。 I have used this in one of my projects and works very fine.
我已经在我的一个项目中使用了它,并且效果很好。
You can define rake tasks in lib/ and in your schedule.rb file which will be generated when you will do whenervize your project. 您可以在lib /和您的schedule.rb文件中定义瑞克任务,这些任务将在您对项目进行服务时生成。
every 3.hours do # 1.minute 1.day 1.week 1.month 1.year is also supported
# your task here
end
every 1.day, :at => '4:30 am' do
# your task here
end
After finishing all you need is to update your crontab file for your machine using this command. 完成所有操作后,您需要使用此命令更新计算机的crontab文件。
$ whenever --update-crontab
Note - just a take care to load proper environment(dev, prod) for the rake tasks, it took me hard to find out when i was trying to run the cron. 注意-请注意为rake任务加载适当的环境(dev,prod),当我尝试运行cron时花了我很多时间。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.