使用 Rails 调度任务

发布于 2024-12-15 12:50:51 字数 540 浏览 1 评论 0原文

我一直在研究 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

池木 2024-12-22 12:50:52

在本例中,Company 是一个示例模型,它具有名为 create_daily_stories! 的类/单例方法。理论上,它可能看起来像这样:

class Company < ActiveRecord::Base

  # Send out daily stories to all companies
  def self.create_daily_stories!
    # Do some stuff
  end
end

理想情况下,生成电子邮件驻留在业务逻辑中,因此应该包含在模型中(假设您使用的是 Rails 等 MVC 框架)。

In this case, Company is an example model that has a class/singleton method called 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).

风吹雨成花 2024-12-22 12:50:52

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文