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
-
.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
- .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
50 51 52 |
# File 'lib/que/scheduler/version_support.rb', line 50 def default_scheduler_queue zero_major? ? "" : Que::DEFAULT_QUEUE 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 |
.que_version ⇒ Object
67 68 69 |
# File 'lib/que/scheduler/version_support.rb', line 67 def que_version @que_version ||= Gem.loaded_specs["que"].version.to_s end |
.running_synchronously? ⇒ Boolean
54 55 56 |
# File 'lib/que/scheduler/version_support.rb', line 54 def running_synchronously? zero_major? ? (Que.mode == :sync) : Que.run_synchronously end |
.running_synchronously_code? ⇒ Boolean
58 59 60 |
# File 'lib/que/scheduler/version_support.rb', line 58 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
62 63 64 65 |
# File 'lib/que/scheduler/version_support.rb', line 62 def zero_major? # This is the only way to handle beta releases too @zero_major ||= que_version.split(".").first.to_i.zero? end |