Rails 每当 gem:每月 20 日

发布于 2024-11-16 23:12:50 字数 256 浏览 4 评论 0原文

我在互联网上搜索了这一点,并且文档并没有真正具体讨论每月的工作。所以我希望这里有人能告诉我如何做到这一点。

我已经安装了whenever gem,我需要知道的是正确的语法:

every :month, :on => '20th', :at => '02:00' do
  runner "Mailer.send_friend_sheet"
end

希望有人能指出我正确的方向..

谢谢!

I searched all over the internet for this, and the documentation isn't really talking about monthly jobs in specific. So I was hoping that someone here could tell me how to do this.

I've installed the whenever gem and all I need to know is the right syntax for this:

every :month, :on => '20th', :at => '02:00' do
  runner "Mailer.send_friend_sheet"
end

Hope someone can point me in the right direction..

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

浪菊怪哟 2024-11-23 23:12:50

如果您不知道如何使用 ruby​​ 语法,您也可以使用原始 cron 语法。

你想要的看起来像:

every '0 2 20 * *' do
  command "echo 'you can use raw cron syntax too'"
end

这是一个关于如何使用 cron 语法的快速备忘单

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

,无耻地窃取自:http:// /adminschoice.com/crontab-quick-reference

You can use raw cron syntax as well if you cant figure out how to use with ruby syntax.

What you want will look like:

every '0 2 20 * *' do
  command "echo 'you can use raw cron syntax too'"
end

Here is a quick cheatsheet for how to use cron syntax

*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

Shamelessly stolen from: http://adminschoice.com/crontab-quick-reference

玉环 2024-11-23 23:12:50

如果您希望它更具可读性,您也可以只解析文本中的日期。

every 1.month, :at => 'January 20th 2:00am' do
  runner "Mailer.send_friend_sheet"
end

这也会生成 0 2 20 * *

If you want it more readable you can also just parse a date in text.

every 1.month, :at => 'January 20th 2:00am' do
  runner "Mailer.send_friend_sheet"
end

This will generate 0 2 20 * * as well.

把昨日还给我 2024-11-23 23:12:50

更好的是:

every 1.month, at: 'start of the month at 2am' do
  runner "Mailer.send_friend_sheet"
end

Even better:

every 1.month, at: 'start of the month at 2am' do
  runner "Mailer.send_friend_sheet"
end
时光倒影 2024-11-23 23:12:50

据我所知,每当不支持 :on 选项,但您应该能够执行

every '0 2 20 * *' do
  runner "Mailer.send_friend_sheet"
end

“0 2 20 * *”只是相关的 cron 语法 - 请参阅 http://www.manpagez.com/man/5/crontab/

Whenever doesn't support an :on option as far as I am aware, but you should be able to do

every '0 2 20 * *' do
  runner "Mailer.send_friend_sheet"
end

The '0 2 20 * *' is simply the relevant cron syntax - see http://www.manpagez.com/man/5/crontab/

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