# 如何安排一个作业每天在特定时间精确运行？

**URL:** <https://meta.discourse.org/t/how-can-i-schedule-a-job-to-run-daily-at-exactly-the-specific-time/194375>\
**Category:** Development\
**Created:** [2021年六月19日 06:04 UTC](https://meta.discourse.org/t/how-can-i-schedule-a-job-to-run-daily-at-exactly-the-specific-time/194375 "2021-06-19T06:04:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyd504](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hyd504/32/177122_2.png) [@hyd504](https://meta.discourse.org/u/hyd504)\
**Post date:** [2021年六月19日 06:04 UTC](https://meta.discourse.org/t/how-can-i-schedule-a-job-to-run-daily-at-exactly-the-specific-time/194375/1 "2021-06-19T06:04:56Z")

</div>

我曾见过如何创建按指定间隔运行的任务示例，例如：

```
after_initialize do
    module ::Jobs
        class PluginTestJob < ::Jobs::Scheduled
            every 30.seconds
            def execute(args)
                puts "Get the job done"
            end
        end
    end
end

```

我想知道如何安排任务在每天太平洋时间的确切时间（例如晚上 9 点）运行。

---

<div class="post-metadata">

**Author:** ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)\
**Post date:** [2021年六月19日 14:30 UTC](https://meta.discourse.org/t/how-can-i-schedule-a-job-to-run-daily-at-exactly-the-specific-time/194375/3 "2021-06-19T14:30:46Z")

</div>

不要使用

> [@hyd504](#):
>
> `every 30.seconds`

而是使用 `daily at: 12.hours`，例如在每天午夜运行一次任务。

您可以在此了解更多：

> **[GitHub - discourse/mini\_scheduler: Adds recurring jobs for Sidekiq](https://github.com/discourse/mini_scheduler)**
>
> Adds recurring jobs for Sidekiq

---

<div class="post-metadata">

**Author:** ![hyd504](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hyd504/32/177122_2.png) [@hyd504](https://meta.discourse.org/u/hyd504)\
**Post date:** [2021年六月19日 14:45 UTC](https://meta.discourse.org/t/how-can-i-schedule-a-job-to-run-daily-at-exactly-the-specific-time/194375/4 "2021-06-19T14:45:56Z")

</div>

谢谢，@Falco！它使用哪个时区，或者有办法指定时区吗？

---

<div class="post-metadata">

**Author:** ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)\
**Post date:** [2021年六月20日 09:55 UTC](https://meta.discourse.org/t/how-can-i-schedule-a-job-to-run-daily-at-exactly-the-specific-time/194375/5 "2021-06-20T09:55:39Z")

</div>

太棒了。超级方便。谢谢提供这些信息。
