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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b426bc239a8d5810c33e8df0d62350ec1556c2a
4
- data.tar.gz: 15dedc3ff27d43206d7fb9e7c97f592d3cb4847e
3
+ metadata.gz: 3ac42dcccc27269cd2422b34c0289a65465e1525
4
+ data.tar.gz: b85f258df6a12f9b21eae3da99c899c7cc1d0003
5
5
  SHA512:
6
- metadata.gz: b87c40dd29f3aad6e85fa170bf0c855809cabbfa0a7f3793c2d19497b11def0f357135b3e13bf5a3eb5f865677314fbb8fd2b62a56450fe209f60a042fc1ab38
7
- data.tar.gz: d7b98ae64b2c6b5400ba1e2e40b0dd7003f5545075926b16537c4ed70d4107ad633043fdcf7c5856ff18821544cdcac1cc59e72accf00fb5d5874420bfd23cc2
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, `unmissable: true`. 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 unmissable jobs, they are always enqueued with the first
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
- unmissable: true
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 Fail-Over
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 :unmissable, default: false
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 "unmissable" then we schedule all of them, with the missed time as an arg,
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.unmissable
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
- def self.defined_jobs
13
- @defined_jobs ||= YAML.load_file(QUE_SCHEDULER_CONFIG_LOCATION).map do |k, v|
14
- Que::Scheduler::DefinedJob.new(
15
- {
16
- name: k,
17
- job_class: v['class'] || k,
18
- queue: v['queue'],
19
- args: v['args'],
20
- priority: v['priority'],
21
- cron: v['cron'],
22
- unmissable: v['unmissable']
23
- }.compact
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
@@ -1,5 +1,5 @@
1
1
  module Que
2
2
  module Scheduler
3
- VERSION = '0.9.1'.freeze
3
+ VERSION = '0.10.1'.freeze
4
4
  end
5
5
  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: 0.9.1
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harry Lascelles