que-scheduler 0.9.1 → 0.10.1
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 +4 -4
- data/README.md +19 -5
- data/lib/que/scheduler/defined_job.rb +8 -1
- data/lib/que/scheduler/enqueueing_calculator.rb +2 -2
- data/lib/que/scheduler/schedule_parser.rb +26 -13
- data/lib/que/scheduler/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ac42dcccc27269cd2422b34c0289a65465e1525
|
4
|
+
data.tar.gz: b85f258df6a12f9b21eae3da99c899c7cc1d0003
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05a947e009768f38ff16b41ed9fa4b1a3c30255cdba0532a6b4e614ce1fca56f642b0dc4cdfb74ee3a3b504382b3d2486e244f9fc41c444cd2ce8b4899c01813
|
7
|
+
data.tar.gz: 69d0447fac46a6e625d357c018874e1d0eedf61d221b12d5ec3299e3ff4ffd476a14f96212fc451b885f784b5d66cc20fb481fcc666879e7ce67906c4f4cddc7
|
data/README.md
CHANGED
@@ -35,8 +35,8 @@ The schedule file is a list of que job classes with arguments and a schedule fre
|
|
35
35
|
syntax). The format is a superset of the resque-scheduler config format, so it they can be used
|
36
36
|
as-is with no modification, assuming the job classes are migrated from Resque to Que.
|
37
37
|
|
38
|
-
It has one additional feature, `
|
39
|
-
single matching cron time that goes by, even if the system is offline over more than one match. To better process these
|
38
|
+
It has one additional feature, `schedule_type: every_event`. This is set on a job that must be run for every
|
39
|
+
single matching cron time that goes by, even if the system is offline over more than one match. To better process these `every_event` jobs, they are always enqueued with the first
|
40
40
|
argument being the time that they were supposed to be processed.
|
41
41
|
|
42
42
|
For example:
|
@@ -78,22 +78,36 @@ DailyBatchReport:
|
|
78
78
|
cron: "0 3 * * *"
|
79
79
|
# This job will be run every day, and if workers are offline for several days, then the backlog
|
80
80
|
# will all be scheduled when they are restored, each with that events timestamp as the first arg.
|
81
|
-
|
81
|
+
schedule_type: every_event
|
82
82
|
```
|
83
83
|
|
84
|
+
## Schedule types
|
85
|
+
|
86
|
+
A job can have a `schedule_type` assigned to it. Valid values are:
|
87
|
+
|
88
|
+
1. `default` - This job will be scheduled when a worker becomes available. If multiple cron times
|
89
|
+
go by during an extended period of downtime then only one job will be enqueued. This is closer to
|
90
|
+
how ordinary cron works.
|
91
|
+
1. `every_event` - This job will always be scheduled with an ISO8601 time as the first argument.
|
92
|
+
If multiple cron times go by during an extended period of downtime, then a job will be scheduled
|
93
|
+
for every one missed. This schedule_type should be used for daily batch jobs that need to know
|
94
|
+
which day they are running a batch for.
|
95
|
+
|
84
96
|
## Environment Variables
|
85
97
|
|
86
98
|
You can configure some aspects of the gem with environment variables.
|
87
99
|
|
88
100
|
* `QUE_SCHEDULER_CONFIG_LOCATION` - The location of the schedule configuration (default `config/que_schedule.yml`)
|
89
101
|
|
90
|
-
## Redundancy and
|
102
|
+
## HA Redundancy and DB restores
|
91
103
|
|
92
104
|
Because of the way que-scheduler works, it requires no additional processes. It is, itself, a Que job.
|
93
105
|
As long as there are Que workers functioning, then jobs will continue to be scheduled correctly. There
|
94
106
|
are no HA concerns to worry about and no namespace collisions between different databases.
|
95
107
|
|
96
|
-
Additionally, like Que, when your database is backed up, your scheduling state is stored too.
|
108
|
+
Additionally, like Que, when your database is backed up, your scheduling state is stored too. If your
|
109
|
+
workers are down for an extended period, or a DB restore is performed, the scheduler will always be
|
110
|
+
in a coherent state with the rest of your database.
|
97
111
|
|
98
112
|
## Multiple scheduler detection
|
99
113
|
|
@@ -7,6 +7,11 @@ module Que
|
|
7
7
|
class DefinedJob < Hashie::Dash
|
8
8
|
include Hashie::Extensions::Dash::PropertyTranslation
|
9
9
|
|
10
|
+
SCHEDULE_TYPES = [
|
11
|
+
SCHEDULE_TYPE_DEFAULT = :default,
|
12
|
+
SCHEDULE_TYPE_EVERY_EVENT = :every_event
|
13
|
+
].freeze
|
14
|
+
|
10
15
|
def self.err_field(f, v)
|
11
16
|
suffix = 'in que-scheduler config ' \
|
12
17
|
"#{Que::Scheduler::ScheduleParser::QUE_SCHEDULER_CONFIG_LOCATION}"
|
@@ -22,7 +27,9 @@ module Que
|
|
22
27
|
property :queue, transform_with: ->(v) { v.is_a?(String) ? v : err_field(:queue, v) }
|
23
28
|
property :priority, transform_with: ->(v) { v.is_a?(Integer) ? v : err_field(:priority, v) }
|
24
29
|
property :args
|
25
|
-
property :
|
30
|
+
property :schedule_type, default: SCHEDULE_TYPE_DEFAULT, transform_with: lambda { |v|
|
31
|
+
v.to_sym.tap { |vs| SCHEDULE_TYPES.include?(vs) || err_field(:schedule_type, v) }
|
32
|
+
}
|
26
33
|
|
27
34
|
# Given a "last time", return the next Time the event will occur, or nil if it
|
28
35
|
# is after "to".
|
@@ -13,7 +13,7 @@ module Que
|
|
13
13
|
|
14
14
|
# For each scheduled item, we need not schedule a job it if it has no history, as it is
|
15
15
|
# new. Otherwise, check how many times we have missed the job since the last run time.
|
16
|
-
# If it is "
|
16
|
+
# If it is "every_event" then we schedule all of them, with the missed time as an arg,
|
17
17
|
# otherwise just schedule it once.
|
18
18
|
scheduler_config.each do |desc|
|
19
19
|
job_name = desc.name
|
@@ -60,7 +60,7 @@ module Que
|
|
60
60
|
priority: desc.priority
|
61
61
|
}.compact
|
62
62
|
|
63
|
-
if desc.
|
63
|
+
if desc.schedule_type == DefinedJob::SCHEDULE_TYPE_EVERY_EVENT
|
64
64
|
missed_times.each do |time_missed|
|
65
65
|
jobs_for_class << options.merge(args: [time_missed] + (desc.args || []))
|
66
66
|
end
|
@@ -9,19 +9,32 @@ module Que
|
|
9
9
|
QUE_SCHEDULER_CONFIG_LOCATION =
|
10
10
|
ENV.fetch('QUE_SCHEDULER_CONFIG_LOCATION', 'config/que_schedule.yml')
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
class << self
|
13
|
+
def defined_jobs
|
14
|
+
@defined_jobs ||= YAML.load_file(QUE_SCHEDULER_CONFIG_LOCATION).map do |k, v|
|
15
|
+
Que::Scheduler::DefinedJob.new(
|
16
|
+
{
|
17
|
+
name: k,
|
18
|
+
job_class: v['class'] || k,
|
19
|
+
queue: v['queue'],
|
20
|
+
args: v['args'],
|
21
|
+
priority: v['priority'],
|
22
|
+
cron: v['cron'],
|
23
|
+
schedule_type: schedule_type(v)
|
24
|
+
}.compact
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# Migrate legacy config that used the `unmissable` config key.
|
32
|
+
def schedule_type(v)
|
33
|
+
if v['unmissable']
|
34
|
+
DefinedJob::SCHEDULE_TYPE_EVERY_EVENT
|
35
|
+
else
|
36
|
+
v['schedule_type'] || DefinedJob::SCHEDULE_TYPE_DEFAULT
|
37
|
+
end
|
25
38
|
end
|
26
39
|
end
|
27
40
|
end
|