que-scheduler 9.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: 43c9761073fc43892c380b61ea7aeadb456c19b1f3d992eca44f93b7ec41c757
4
- data.tar.gz: e7897e20ca62c7183f6db25289dc1781e825193238b1a0687eabe2ced6a3dcf5
3
+ metadata.gz: ffc35188a40ca5e846bcaf011d61c3fdec92105055d04f8059dfabcc37fdd4f1
4
+ data.tar.gz: be97d1b4732e85f3557e5ec95290cce3b86a485d74c260d2288dfbae1d7e82dc
5
5
  SHA512:
6
- metadata.gz: 3f5b2b777d5e52aff1d6422a84569b048db2b544e7b17457f1c413e5caa11d0505e90540a75264cd2fdecbdeb621a3f326f1591e5ff355169ecb1eba6b867d9d
7
- data.tar.gz: 4b6ddb6b440fb761cecb48cdc815ecde9b1963535d2eb919b2f630ba899f54d6c21ace7c37a93258faa85c41f02164a0e52e1f8f5727a81e4148485b92811133
6
+ metadata.gz: bf1094a2a1472bd51606888d2cfed1c654a43b1a3241b80cfedac0eab173c12f14da792ad02602ca285d096acd4163b1c5033e8d443ac1087bbc8a015d2d3b89
7
+ data.tar.gz: e37d2e1e3f9bf23ed2234b65718174dba238eadcf7de890b1624800fd8cd32db015e0498fc5fe6194fb51403b1047743c771d24dc7682e327692620a9d57d5a4
data/README.md CHANGED
@@ -28,7 +28,7 @@ resque-scheduler files, but with additional features.
28
28
  ```ruby
29
29
  class CreateQueSchedulerSchema < ActiveRecord::Migration[6.0]
30
30
  def change
31
- Que::Scheduler::Migrations.migrate!(version: 8)
31
+ Que::Scheduler::Migrations.migrate!(version: 9)
32
32
  Que::Scheduler::Migrations.reenqueue_scheduler_if_missing
33
33
  end
34
34
  end
@@ -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).
@@ -216,7 +233,7 @@ performed.
216
233
  ```ruby
217
234
  class CreateQueSchedulerSchema < ActiveRecord::Migration[6.0]
218
235
  def change
219
- Que::Scheduler::Migrations.migrate!(version: 8)
236
+ Que::Scheduler::Migrations.migrate!(version: 9)
220
237
  Que::Scheduler::Migrations.reenqueue_scheduler_if_missing
221
238
  end
222
239
  end
@@ -234,6 +251,7 @@ The changes in past migrations were:
234
251
  | 6 | Enforced single scheduler job at the trigger level |
235
252
  | 7 | Prevent accidental deletion of scheduler job |
236
253
  | 8 | Add primary key to audit. Note, this can be a slow migration if you have many rows! |
254
+ | 9 | Index `que_scheduler_audit_enqueued.scheduler_job_id` to speed up audit clear down |
237
255
 
238
256
  The changes to the DB ([DDL](https://en.wikipedia.org/wiki/Data_definition_language)) are all
239
257
  captured in the structure.sql so will be re-run in correctly if squashed - except for the actual
@@ -0,0 +1 @@
1
+ DROP INDEX que_scheduler_audit_enqueued_scheduler_job_id;
@@ -0,0 +1 @@
1
+ CREATE INDEX IF NOT EXISTS que_scheduler_audit_enqueued_scheduler_job_id ON que_scheduler_audit_enqueued USING btree (scheduler_job_id);
@@ -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 = "9.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: 9.0.0
4
+ version: 10.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Lascelles
@@ -399,6 +399,8 @@ files:
399
399
  - lib/que/scheduler/migrations/7/up.sql
400
400
  - lib/que/scheduler/migrations/8/down.sql
401
401
  - lib/que/scheduler/migrations/8/up.sql
402
+ - lib/que/scheduler/migrations/9/down.sql
403
+ - lib/que/scheduler/migrations/9/up.sql
402
404
  - lib/que/scheduler/schedule.rb
403
405
  - lib/que/scheduler/schedule_type.rb
404
406
  - lib/que/scheduler/scheduler_job.rb