que-scheduler 10.0.0 → 10.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab54c19040f766a045ed5d8b36c6204a69fa908add11f02c6f1d30f354c6235d
4
- data.tar.gz: 6cd41e7125e7d964dfcde0fcdab30cf9a1a1ab25a4a690288504b8252f495f08
3
+ metadata.gz: ffc35188a40ca5e846bcaf011d61c3fdec92105055d04f8059dfabcc37fdd4f1
4
+ data.tar.gz: be97d1b4732e85f3557e5ec95290cce3b86a485d74c260d2288dfbae1d7e82dc
5
5
  SHA512:
6
- metadata.gz: 59738cdf4bd5c93a252b70dd09fc9c3fd3a1d9bbba1595794c33cb18fc4fe11c4be48dbdd29685709a739739cd37a83ab8915d528f5f8e8a832257425bcc04a8
7
- data.tar.gz: 68517d04f22ebd27ddfb987a70db9cdc0e20b526e171e4e6180c27233f4d80421ce6f347f649a85a76e6b504d28c47383a01bb8c33d4b00d6a784129c67f478a
6
+ metadata.gz: bf1094a2a1472bd51606888d2cfed1c654a43b1a3241b80cfedac0eab173c12f14da792ad02602ca285d096acd4163b1c5033e8d443ac1087bbc8a015d2d3b89
7
+ data.tar.gz: e37d2e1e3f9bf23ed2234b65718174dba238eadcf7de890b1624800fd8cd32db015e0498fc5fe6194fb51403b1047743c771d24dc7682e327692620a9d57d5a4
data/README.md CHANGED
@@ -96,6 +96,10 @@ SendBilling:
96
96
  SendCoupons:
97
97
  cron: "0 7 * * * America/Los_Angeles"
98
98
 
99
+ # Use a seconds field (see "Sub-minute schedules" below)
100
+ HealthCheck:
101
+ cron: "*/15 * * * * *"
102
+
99
103
  # Altogether now
100
104
  all_options_job:
101
105
  cron: "0 0 * * *"
@@ -137,6 +141,19 @@ A job can have a `schedule_type` assigned to it. Valid values are:
137
141
  This feature ensures that jobs which *must run* for a certain cron match will always eventually
138
142
  execute, even after a total system crash, or even a DB backup restore.
139
143
 
144
+ ## Sub-minute schedules
145
+
146
+ The scheduler normally runs once a minute. If a job's cron has a seconds field and is due before the next
147
+ minute, the scheduler runs early to enqueue it on time, and returns to once a minute when nothing is
148
+ due sooner. Note:
149
+
150
+ 1. Que only picks up jobs scheduled in the future when it polls, every 5 seconds by default. For
151
+ finer precision, lower Que's `poll_interval`.
152
+ 1. Every scheduler run is a DB transaction and writes a row to the audit table, so frequent schedules
153
+ add load and audit rows. Consider scheduling the [audit clear down job](#scheduler-audit).
154
+ 1. As with any new job, a new schedule takes effect on the scheduler's next run after deploy, so
155
+ up to a minute later.
156
+
140
157
  ## Gem configuration
141
158
 
142
159
  You can configure some aspects of the gem with a config block (eg in a Rails initializer).
@@ -13,8 +13,8 @@ require_relative "to_enqueue"
13
13
  require_relative "db_support"
14
14
  require_relative "types"
15
15
 
16
- # The main job that runs every minute, determining what needs to be enqueued, enqueues the required
17
- # jobs, then re-enqueues itself.
16
+ # The main job that runs every minute (or sooner if a job is due), determining what needs to be
17
+ # enqueued, enqueues the required jobs, then re-enqueues itself.
18
18
  module Que
19
19
  module Scheduler
20
20
  class SchedulerJob < Que::Job
@@ -96,12 +96,11 @@ module Que
96
96
  Audit.append(job_id, scheduler_job_args.as_time, enqueued_jobs)
97
97
 
98
98
  # And rerun...
99
- next_run_at = scheduler_job_args.as_time.beginning_of_minute + SCHEDULER_FREQUENCY
100
99
  enqueued_job = Que::Scheduler::DbSupport.enqueue_a_job(
101
100
  SchedulerJob,
102
101
  {
103
102
  queue: Que::Scheduler.configuration.que_scheduler_queue,
104
- run_at: next_run_at,
103
+ run_at: next_run_at(scheduler_job_args.as_time),
105
104
  },
106
105
  [{ last_run_time: last_full_execution.iso8601, job_dictionary: job_dictionary }]
107
106
  )
@@ -110,6 +109,14 @@ module Que
110
109
 
111
110
  raise "SchedulerJob could not self-schedule. Has `.enqueue` been monkey patched?"
112
111
  end
112
+
113
+ # Run again at the next minute, or sooner if a job (eg a seconds cron) is due before then
114
+ sig { params(as_time: Types::TIME).returns(Types::TIME) }
115
+ private def next_run_at(as_time)
116
+ next_minute = as_time.beginning_of_minute + SCHEDULER_FREQUENCY
117
+ due_sooner = Scheduler.schedule.values.filter_map { it.next_run_time(as_time, next_minute) }
118
+ T.must([next_minute, *due_sooner].min)
119
+ end
113
120
  end
114
121
  end
115
122
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Que
4
4
  module Scheduler
5
- VERSION = "10.0.0".freeze
5
+ VERSION = "10.1.0".freeze
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: que-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.0
4
+ version: 10.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Lascelles