使用 Rails 调度任务
我一直在研究 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
我对 ruby 相当陌生,不太明白这里的“公司”代表什么。换句话说,我想向人们发送电子邮件,并且我有一个名为 email_controller 的控制器类,其中我有一个名为 sendEmail 的方法,并且我想使用它发送电子邮件,我该怎么做?我应该说 runner"email_controller.sendEmail" 还是类似的东西?我不太明白。注意 - 我是否使用模型或控制器代替公司?
I have been going over rails scheduling tasks options and stumbled upon this piece of code from whenever.
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? Should i say runner"email_controller.sendEmail" or something like that? I dont quite get it. Note - Do i use the model or controller in place of company?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在本例中,
Company
是一个示例模型,它具有名为create_daily_stories!
的类/单例方法。理论上,它可能看起来像这样:理想情况下,生成电子邮件驻留在业务逻辑中,因此应该包含在模型中(假设您使用的是 Rails 等 MVC 框架)。
In this case,
Company
is an example model that has a class/singleton method calledcreate_daily_stories!
. In theory, it would probably look like this: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).
Resque 是安排任务的好方法。
看看 Resque Railscast。
或者可能是这个Rails:使用 Redis、Resque 和 Rufus 进行 Cron 作业调度。
Resque is a great way to schedule tasks.
Take a look at Resque Railscast.
or possibly this Rails: Cron Job Scheduling using Redis, Resque and Rufus.