que-scheduler 3.2.1 → 3.2.2
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 +28 -0
 - data/lib/que/scheduler/defined_job.rb +6 -23
 - data/lib/que/scheduler/migrations.rb +3 -0
 - data/lib/que/scheduler/schedule.rb +51 -0
 - data/lib/que/scheduler/scheduler_job.rb +2 -2
 - data/lib/que/scheduler/version.rb +1 -1
 - metadata +3 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 2b504deabde4b9902e95944af14f2bd0820c6e7e
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9cecf4a0dcf0f6497096d0dfe5824c1452447c53
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: f2ebae7e9453682a6ed07f84b46523e1a617df42d9ed1aca8f60abb314080a5285067c56bcbaafa6d908d5adf26e90ba810afa90d31c7ac9a5c8a6f36ab8d009
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3b6425695eaaa1519a8cb4ec579bb40e9eb5a3a4514ffc5bc74218f884f43cb0ee884b2c329753107f56fe1f0d0743bca7a975a5c41e175e9cb86da9e0c5fdd3
         
     | 
    
        data/README.md
    CHANGED
    
    | 
         @@ -183,6 +183,34 @@ As of migration `4`, two elements are added to the DB for que-scheduler to run. 
     | 
|
| 
       183 
183 
     | 
    
         
             
              `que_scheduler_audit_enqueued`. The first tracks when the scheduler calculated what was necessary to run 
         
     | 
| 
       184 
184 
     | 
    
         
             
              (if anything). The second then logs every job that the scheduler enqueues. 
         
     | 
| 
       185 
185 
     | 
    
         | 
| 
      
 186 
     | 
    
         
            +
            ## Testing Configuration
         
     | 
| 
      
 187 
     | 
    
         
            +
             
     | 
| 
      
 188 
     | 
    
         
            +
            You can add tests to validate your configuration during the spec phase. This will perform a variety 
         
     | 
| 
      
 189 
     | 
    
         
            +
            of sanity checks and ensure that:
         
     | 
| 
      
 190 
     | 
    
         
            +
             
     | 
| 
      
 191 
     | 
    
         
            +
            1. The yml is present and valid
         
     | 
| 
      
 192 
     | 
    
         
            +
            1. The job classes exist and are descendants of Que::Job
         
     | 
| 
      
 193 
     | 
    
         
            +
            1. The cron fields are present and valid
         
     | 
| 
      
 194 
     | 
    
         
            +
            1. The queues (if present) are strings
         
     | 
| 
      
 195 
     | 
    
         
            +
            1. The priorities (if present) are integers
         
     | 
| 
      
 196 
     | 
    
         
            +
            1. The schedule_types are known
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 199 
     | 
    
         
            +
             
     | 
| 
      
 200 
     | 
    
         
            +
              describe 'check que_schedule.yml' do
         
     | 
| 
      
 201 
     | 
    
         
            +
                it 'loads the schedule from the default location' do
         
     | 
| 
      
 202 
     | 
    
         
            +
                  # Will raise an error if any config is invalid
         
     | 
| 
      
 203 
     | 
    
         
            +
                  expect(Que::Scheduler.schedule).not_to be nil
         
     | 
| 
      
 204 
     | 
    
         
            +
                end
         
     | 
| 
      
 205 
     | 
    
         
            +
              end
         
     | 
| 
      
 206 
     | 
    
         
            +
            ```
         
     | 
| 
      
 207 
     | 
    
         
            +
             
     | 
| 
      
 208 
     | 
    
         
            +
            ## Error Notification
         
     | 
| 
      
 209 
     | 
    
         
            +
             
     | 
| 
      
 210 
     | 
    
         
            +
            If there is an error during scheduling, que-scheduler will report it using the [standard que error
         
     | 
| 
      
 211 
     | 
    
         
            +
            notifier](https://github.com/chanks/que/blob/master/docs/error_handling.md#error-notifications).
         
     | 
| 
      
 212 
     | 
    
         
            +
            The scheduler will then continue to retry indefinitely.
         
     | 
| 
      
 213 
     | 
    
         
            +
             
     | 
| 
       186 
214 
     | 
    
         
             
            ## Upgrading
         
     | 
| 
       187 
215 
     | 
    
         | 
| 
       188 
216 
     | 
    
         
             
            que-scheduler uses [semantic versioning](https://semver.org/), so major version changes will usually 
         
     | 
| 
         @@ -8,9 +8,9 @@ module Que 
     | 
|
| 
       8 
8 
     | 
    
         
             
                class DefinedJob < Hashie::Dash
         
     | 
| 
       9 
9 
     | 
    
         
             
                  include Hashie::Extensions::Dash::PropertyTranslation
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                   
     | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
       13 
     | 
    
         
            -
                     
     | 
| 
      
 11 
     | 
    
         
            +
                  DEFINED_JOB_TYPES = [
         
     | 
| 
      
 12 
     | 
    
         
            +
                    DEFINED_JOB_TYPE_DEFAULT = :default,
         
     | 
| 
      
 13 
     | 
    
         
            +
                    DEFINED_JOB_TYPE_EVERY_EVENT = :every_event
         
     | 
| 
       14 
14 
     | 
    
         
             
                  ].freeze
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                  property :name, required: true
         
     | 
| 
         @@ -24,8 +24,8 @@ module Que 
     | 
|
| 
       24 
24 
     | 
    
         
             
                  property :queue, transform_with: ->(v) { v.is_a?(String) ? v : err_field(:queue, v) }
         
     | 
| 
       25 
25 
     | 
    
         
             
                  property :priority, transform_with: ->(v) { v.is_a?(Integer) ? v : err_field(:priority, v) }
         
     | 
| 
       26 
26 
     | 
    
         
             
                  property :args
         
     | 
| 
       27 
     | 
    
         
            -
                  property :schedule_type, default:  
     | 
| 
       28 
     | 
    
         
            -
                    v.to_sym.tap { |vs|  
     | 
| 
      
 27 
     | 
    
         
            +
                  property :schedule_type, default: DEFINED_JOB_TYPE_DEFAULT, transform_with: lambda { |v|
         
     | 
| 
      
 28 
     | 
    
         
            +
                    v.to_sym.tap { |vs| DEFINED_JOB_TYPES.include?(vs) || err_field(:schedule_type, v) }
         
     | 
| 
       29 
29 
     | 
    
         
             
                  }
         
     | 
| 
       30 
30 
     | 
    
         | 
| 
       31 
31 
     | 
    
         
             
                  # Given a "last time", return the next Time the event will occur, or nil if it
         
     | 
| 
         @@ -50,23 +50,6 @@ module Que 
     | 
|
| 
       50 
50 
     | 
    
         
             
                  end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
52 
     | 
    
         
             
                  class << self
         
     | 
| 
       53 
     | 
    
         
            -
                    def defined_jobs
         
     | 
| 
       54 
     | 
    
         
            -
                      schedule_string = IO.read(Que::Scheduler.configuration.schedule_location)
         
     | 
| 
       55 
     | 
    
         
            -
                      @defined_jobs ||= YAML.safe_load(schedule_string).map do |k, v|
         
     | 
| 
       56 
     | 
    
         
            -
                        Que::Scheduler::DefinedJob.new(
         
     | 
| 
       57 
     | 
    
         
            -
                          {
         
     | 
| 
       58 
     | 
    
         
            -
                            name: k,
         
     | 
| 
       59 
     | 
    
         
            -
                            job_class: v['class'] || k,
         
     | 
| 
       60 
     | 
    
         
            -
                            queue: v['queue'],
         
     | 
| 
       61 
     | 
    
         
            -
                            args: v['args'],
         
     | 
| 
       62 
     | 
    
         
            -
                            priority: v['priority'],
         
     | 
| 
       63 
     | 
    
         
            -
                            cron: v['cron'],
         
     | 
| 
       64 
     | 
    
         
            -
                            schedule_type: v['schedule_type'],
         
     | 
| 
       65 
     | 
    
         
            -
                          }.compact
         
     | 
| 
       66 
     | 
    
         
            -
                        ).freeze
         
     | 
| 
       67 
     | 
    
         
            -
                      end
         
     | 
| 
       68 
     | 
    
         
            -
                    end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
53 
     | 
    
         
             
                    private
         
     | 
| 
       71 
54 
     | 
    
         | 
| 
       72 
55 
     | 
    
         
             
                    def err_field(field, value)
         
     | 
| 
         @@ -90,7 +73,7 @@ module Que 
     | 
|
| 
       90 
73 
     | 
    
         
             
                    options = to_h.slice(:args, :queue, :priority, :job_class).compact
         
     | 
| 
       91 
74 
     | 
    
         
             
                    args_array = args.is_a?(Array) ? args : Array(args)
         
     | 
| 
       92 
75 
     | 
    
         | 
| 
       93 
     | 
    
         
            -
                    if schedule_type == DefinedJob:: 
     | 
| 
      
 76 
     | 
    
         
            +
                    if schedule_type == DefinedJob::DEFINED_JOB_TYPE_EVERY_EVENT
         
     | 
| 
       94 
77 
     | 
    
         
             
                      missed_times.map do |time_missed|
         
     | 
| 
       95 
78 
     | 
    
         
             
                        ToEnqueue.new(options.merge(args: [time_missed] + args_array))
         
     | 
| 
       96 
79 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -0,0 +1,51 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'defined_job'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module Que
         
     | 
| 
      
 4 
     | 
    
         
            +
              module Scheduler
         
     | 
| 
      
 5 
     | 
    
         
            +
                class Schedule
         
     | 
| 
      
 6 
     | 
    
         
            +
                  class << self
         
     | 
| 
      
 7 
     | 
    
         
            +
                    def schedule
         
     | 
| 
      
 8 
     | 
    
         
            +
                      @schedule ||=
         
     | 
| 
      
 9 
     | 
    
         
            +
                        begin
         
     | 
| 
      
 10 
     | 
    
         
            +
                          location = Que::Scheduler.configuration.schedule_location
         
     | 
| 
      
 11 
     | 
    
         
            +
                          from_file(location)
         
     | 
| 
      
 12 
     | 
    
         
            +
                        end
         
     | 
| 
      
 13 
     | 
    
         
            +
                    end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    def from_file(location)
         
     | 
| 
      
 16 
     | 
    
         
            +
                      yml = IO.read(location)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      config_hash = YAML.safe_load(yml)
         
     | 
| 
      
 18 
     | 
    
         
            +
                      from_hash(config_hash)
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    def from_hash(config_hash)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      config_hash.map do |name, defined_job_hash|
         
     | 
| 
      
 23 
     | 
    
         
            +
                        [name, hash_item_to_defined_job(name, defined_job_hash)]
         
     | 
| 
      
 24 
     | 
    
         
            +
                      end.to_h
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                    private
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                    def hash_item_to_defined_job(name, defined_job_hash)
         
     | 
| 
      
 30 
     | 
    
         
            +
                      Que::Scheduler::DefinedJob.new(
         
     | 
| 
      
 31 
     | 
    
         
            +
                        {
         
     | 
| 
      
 32 
     | 
    
         
            +
                          name: name,
         
     | 
| 
      
 33 
     | 
    
         
            +
                          job_class: defined_job_hash['class'] || name,
         
     | 
| 
      
 34 
     | 
    
         
            +
                          queue: defined_job_hash['queue'],
         
     | 
| 
      
 35 
     | 
    
         
            +
                          args: defined_job_hash['args'],
         
     | 
| 
      
 36 
     | 
    
         
            +
                          priority: defined_job_hash['priority'],
         
     | 
| 
      
 37 
     | 
    
         
            +
                          cron: defined_job_hash['cron'],
         
     | 
| 
      
 38 
     | 
    
         
            +
                          schedule_type: defined_job_hash['schedule_type'],
         
     | 
| 
      
 39 
     | 
    
         
            +
                        }.compact
         
     | 
| 
      
 40 
     | 
    
         
            +
                      ).freeze
         
     | 
| 
      
 41 
     | 
    
         
            +
                    end
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 46 
     | 
    
         
            +
                  def schedule
         
     | 
| 
      
 47 
     | 
    
         
            +
                    Schedule.schedule
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,6 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'que'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            require_relative ' 
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'schedule'
         
     | 
| 
       4 
4 
     | 
    
         
             
            require_relative 'enqueueing_calculator'
         
     | 
| 
       5 
5 
     | 
    
         
             
            require_relative 'scheduler_job_args'
         
     | 
| 
       6 
6 
     | 
    
         
             
            require_relative 'state_checks'
         
     | 
| 
         @@ -22,7 +22,7 @@ module Que 
     | 
|
| 
       22 
22 
     | 
    
         
             
                      scheduler_job_args = SchedulerJobArgs.build(options)
         
     | 
| 
       23 
23 
     | 
    
         
             
                      logs = ["que-scheduler last ran at #{scheduler_job_args.last_run_time}."]
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
                      result = EnqueueingCalculator.parse( 
     | 
| 
      
 25 
     | 
    
         
            +
                      result = EnqueueingCalculator.parse(Scheduler.schedule.values, scheduler_job_args)
         
     | 
| 
       26 
26 
     | 
    
         
             
                      enqueued_jobs = enqueue_required_jobs(result, logs)
         
     | 
| 
       27 
27 
     | 
    
         
             
                      enqueue_self_again(
         
     | 
| 
       28 
28 
     | 
    
         
             
                        scheduler_job_args, scheduler_job_args.as_time, result.job_dictionary, enqueued_jobs
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: que-scheduler
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 3.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 3.2.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Harry Lascelles
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2018- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-08-01 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activesupport
         
     | 
| 
         @@ -328,6 +328,7 @@ files: 
     | 
|
| 
       328 
328 
     | 
    
         
             
            - lib/que/scheduler/migrations/3/up.sql
         
     | 
| 
       329 
329 
     | 
    
         
             
            - lib/que/scheduler/migrations/4/down.sql
         
     | 
| 
       330 
330 
     | 
    
         
             
            - lib/que/scheduler/migrations/4/up.sql
         
     | 
| 
      
 331 
     | 
    
         
            +
            - lib/que/scheduler/schedule.rb
         
     | 
| 
       331 
332 
     | 
    
         
             
            - lib/que/scheduler/scheduler_job.rb
         
     | 
| 
       332 
333 
     | 
    
         
             
            - lib/que/scheduler/scheduler_job_args.rb
         
     | 
| 
       333 
334 
     | 
    
         
             
            - lib/que/scheduler/state_checks.rb
         
     |