[英]Scheduling tasks with rails
I have been going over rails scheduling tasks options and stumbled upon this piece of code from whenever. 我一直在研究Rails调度任务选项,并从任何时候偶然发现这段代码。
case @environment
when 'production'
every 1.day, :at => "#{Time.parse('12:00 A').getlocal.strftime("%H:%M")}" do
runner "Company.send_later(:create_daily_stories!)"
end
when 'staging'
every 15.minutes do
command "thinking_sphinx_searchd reindex"
end
end
I am fairly new to ruby and I dont quite understand what "Company" here stands for. 我对红宝石还很陌生,我不太了解“公司”在这里的含义。 In other words say i want to send an email out to people and i have a controller class called email_controller in which I have a method called sendEmail and I want to send emails using this how would i do it? 换句话说,我想向人们发送电子邮件,并且我有一个名为email_controller的控制器类,其中有一个名为sendEmail的方法,我想使用此方法发送电子邮件吗? Should i say runner"email_controller.sendEmail" or something like that? 我应该说跑步者“ email_controller.sendEmail”还是类似的东西? I dont quite get it. 我不太明白。 Note - Do i use the model or controller in place of company? 注-我是否使用模型或控制器代替公司?
In this case, Company
is an example model that has a class/singleton method called create_daily_stories!
在这种情况下, Company
是一个示例模型,该模型具有称为create_daily_stories!
的类/单例方法create_daily_stories!
. 。 In theory, it would probably look like this: 从理论上讲,它可能看起来像这样:
class Company < ActiveRecord::Base
# Send out daily stories to all companies
def self.create_daily_stories!
# Do some stuff
end
end
Ideally, generating emails resides in the business logic and should thusly be contained within a model (assuming you're using an MVC framework like rails). 理想情况下,生成电子邮件驻留在业务逻辑中,因此应包含在模型中(假设您使用的是像Rails这样的MVC框架)。
Resque is a great way to schedule tasks. Resque是安排任务的好方法。
Take a look at Resque Railscast . 看看Resque Railscast 。
or possibly this Rails: Cron Job Scheduling using Redis, Resque and Rufus . 或可能使用Rails:使用Redis,Resque和Rufus进行Cron作业调度 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.