Module: Que::Scheduler::VersionSupport
- Defined in:
- lib/que/scheduler/version_support.rb
Constant Summary collapse
- RETRY_PROC =
proc { |count| # Maximum one hour, otherwise use the default backoff count > 7 ? (60 * 60) : ((count**4) + 3) }
Class Method Summary collapse
-
.apply_retry_semantics(context) ⇒ Object
Ensure the job runs at least once an hour when it is backing off due to errors.
-
.default_scheduler_queue ⇒ Object
rubocop:enable Style/IfInsideElse.
-
.enqueue_a_job(clazz, job_options = {}, job_args = []) ⇒ Object
rubocop:disable Style/IfInsideElse.
-
.execute(str, args = []) ⇒ Object
Between Que 0.x and 1.x the result of Que execute changed keys from strings to symbols.
- .job_attributes(enqueued_job) ⇒ Object
- .one_major? ⇒ Boolean
- .que_version ⇒ Object
- .running_synchronously? ⇒ Boolean
- .running_synchronously_code? ⇒ Boolean
-
.set_priority(context, priority) ⇒ Object
Ensure que-scheduler runs at the highest priority.
- .zero_major? ⇒ Boolean
Class Method Details
.apply_retry_semantics(context) ⇒ Object
Ensure the job runs at least once an hour when it is backing off due to errors
25 26 27 28 29 30 31 32 |
# File 'lib/que/scheduler/version_support.rb', line 25 def apply_retry_semantics(context) if zero_major? context.instance_variable_set(:@retry_interval, RETRY_PROC) else context.maximum_retry_count = 1 << 128 # Heat death of universe context.retry_interval = RETRY_PROC end end |
.default_scheduler_queue ⇒ Object
rubocop:enable Style/IfInsideElse
69 70 71 |
# File 'lib/que/scheduler/version_support.rb', line 69 def default_scheduler_queue zero_major? ? "" : Que::DEFAULT_QUEUE end |
.enqueue_a_job(clazz, job_options = {}, job_args = []) ⇒ Object
rubocop:disable Style/IfInsideElse
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/que/scheduler/version_support.rb', line 51 def enqueue_a_job(clazz, = {}, job_args = []) if # More recent versions have separated the way job arguments and options are passed in if job_args.is_a?(Hash) clazz.enqueue(job_args, job_options: ) else clazz.enqueue(*job_args, job_options: ) end else if job_args.is_a?(Hash) clazz.enqueue(**job_args.merge()) else clazz.enqueue(*job_args, **) end end end |
.execute(str, args = []) ⇒ Object
Between Que 0.x and 1.x the result of Que execute changed keys from strings to symbols. Here we wrap the concept and make sure either way produces symbols
46 47 48 |
# File 'lib/que/scheduler/version_support.rb', line 46 def execute(str, args = []) normalise_array_of_hashes(Que.execute(str, args)) end |
.job_attributes(enqueued_job) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/que/scheduler/version_support.rb', line 34 def job_attributes(enqueued_job) if zero_major? enqueued_job.attrs.to_h.transform_keys(&:to_sym) else enqueued_job.que_attrs.to_h.transform_keys(&:to_sym).tap do |hash| hash[:job_id] = hash.delete(:id) end end end |
.one_major? ⇒ Boolean
86 87 88 89 |
# File 'lib/que/scheduler/version_support.rb', line 86 def one_major? # This is the only way to handle beta releases too @one_major ||= que_version.split(".").first.to_i == 1 end |
.que_version ⇒ Object
91 92 93 |
# File 'lib/que/scheduler/version_support.rb', line 91 def que_version @que_version ||= que_version_object.to_s end |
.running_synchronously? ⇒ Boolean
73 74 75 |
# File 'lib/que/scheduler/version_support.rb', line 73 def running_synchronously? zero_major? ? (Que.mode == :sync) : Que.run_synchronously end |
.running_synchronously_code? ⇒ Boolean
77 78 79 |
# File 'lib/que/scheduler/version_support.rb', line 77 def running_synchronously_code? zero_major? ? "Que.mode == :sync" : "Que.run_synchronously = true" end |
.set_priority(context, priority) ⇒ Object
Ensure que-scheduler runs at the highest priority. This is because its priority is a the top of all jobs it enqueues.
16 17 18 19 20 21 22 |
# File 'lib/que/scheduler/version_support.rb', line 16 def set_priority(context, priority) if zero_major? context.instance_variable_set(:@priority, priority) else context.priority = priority end end |
.zero_major? ⇒ Boolean
81 82 83 84 |
# File 'lib/que/scheduler/version_support.rb', line 81 def zero_major? # This is the only way to handle beta releases too @zero_major ||= que_version.split(".").first.to_i.zero? end |