inst-jobs 3.1.8 → 3.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ecc79cbf0af3c0205febacfb4124bf1b86183132fd28f1330b0fb9c097efe62
4
- data.tar.gz: 31f7cb19c7ecc6b71833dcc31b998642fec44e06d1bfbaefc2ed868fe331688a
3
+ metadata.gz: abb4fa28665e7fbe5edcc244f1261e9be5b9b473749739ac21477f4a15f0b9a3
4
+ data.tar.gz: e20096c0cd70ce6e1b231a24c761a89f50cee44ccb7bd80cad567366f9d027f4
5
5
  SHA512:
6
- metadata.gz: 1d76db82af500258ac736d6b3819fffcccc0afe81a4c44cf01c540252695f3a3b2d120c00576f4ee02459e0808ddcb1d19c25ddb16c41945fc103718fa8011e3
7
- data.tar.gz: 6f6efc00e1a707f5e984455db881281f56eac2b06fd17ee75a5a574c883fcdcb7c99b1483d3d3cadb6d501d6ee4c98b031b997e285bdf598bbc257cf6fb83364
6
+ metadata.gz: 7249c4fab5ee3113d50f37991878669703918b984b64e56986958eb0798b233a24d94489534e2dd0c00a252fe62a379957a7f7346306e06e4f93c5f0a411bea0
7
+ data.tar.gz: 5c84ddeace70c4c8cdad94d3b5967025f162e76e4d468fc064b1dd2d9196c442705a6a4b922d45738a8dcc1f733c10ef886d052a839244c3a2fa049efb2d8ca3
@@ -9,7 +9,8 @@ class AddIdToGetDelayedJobsIndex < ActiveRecord::Migration[4.2]
9
9
 
10
10
  def up
11
11
  rename_index :delayed_jobs, "get_delayed_jobs_index", "get_delayed_jobs_index_old"
12
- add_index :delayed_jobs, %i[queue priority run_at id],
12
+ add_index :delayed_jobs,
13
+ %i[queue priority run_at id],
13
14
  algorithm: :concurrently,
14
15
  where: "locked_at IS NULL AND next_in_strand",
15
16
  name: "get_delayed_jobs_index"
@@ -18,7 +19,8 @@ class AddIdToGetDelayedJobsIndex < ActiveRecord::Migration[4.2]
18
19
 
19
20
  def down
20
21
  rename_index :delayed_jobs, "get_delayed_jobs_index", "get_delayed_jobs_index_old"
21
- add_index :delayed_jobs, %i[priority run_at queue],
22
+ add_index :delayed_jobs,
23
+ %i[priority run_at queue],
22
24
  algorithm: :concurrently,
23
25
  where: "locked_at IS NULL AND next_in_strand",
24
26
  name: "get_delayed_jobs_index"
@@ -10,7 +10,8 @@ class AddStrandOrderOverride < ActiveRecord::Migration[4.2]
10
10
  def up
11
11
  add_column :delayed_jobs, :strand_order_override, :integer, default: 0, null: false
12
12
  add_column :failed_jobs, :strand_order_override, :integer, default: 0, null: false
13
- add_index :delayed_jobs, %i[strand strand_order_override id],
13
+ add_index :delayed_jobs,
14
+ %i[strand strand_order_override id],
14
15
  algorithm: :concurrently,
15
16
  where: "strand IS NOT NULL",
16
17
  name: "next_in_strand_index"
@@ -4,7 +4,8 @@ class AddNStrandIndex < ActiveRecord::Migration[5.2]
4
4
  disable_ddl_transaction!
5
5
 
6
6
  def change
7
- add_index :delayed_jobs, %i[strand next_in_strand id],
7
+ add_index :delayed_jobs,
8
+ %i[strand next_in_strand id],
8
9
  name: "n_strand_index",
9
10
  where: "strand IS NOT NULL",
10
11
  algorithm: :concurrently
@@ -115,7 +115,7 @@ module Delayed
115
115
  # but we don't need to lock when inserting into Delayed::Failed
116
116
  if values["strand"] && instance_of?(Job)
117
117
  fn_name = connection.quote_table_name("half_md5_as_bigint")
118
- quoted_strand = connection.quote(Rails.version < "7.0" ? values["strand"] : values["strand"].value)
118
+ quoted_strand = connection.quote((Rails.version < "7.0") ? values["strand"] : values["strand"].value)
119
119
  sql = "SELECT pg_advisory_xact_lock(#{fn_name}(#{quoted_strand})); #{sql}"
120
120
  end
121
121
  result = connection.execute(sql, "#{self.class} Create")
@@ -253,7 +253,7 @@ module Delayed
253
253
  offset = 0,
254
254
  query = nil)
255
255
  scope = scope_for_flavor(flavor, query)
256
- order = flavor.to_s == "future" ? "run_at" : "id desc"
256
+ order = (flavor.to_s == "future") ? "run_at" : "id desc"
257
257
  scope.order(order).limit(limit).offset(offset).to_a
258
258
  end
259
259
 
@@ -607,7 +607,12 @@ module Delayed
607
607
  end
608
608
 
609
609
  def requeue!
610
- attrs = attributes.except("id", "last_error", "locked_at", "failed_at", "locked_by", "original_job_id",
610
+ attrs = attributes.except("id",
611
+ "last_error",
612
+ "locked_at",
613
+ "failed_at",
614
+ "locked_by",
615
+ "original_job_id",
611
616
  "requeued_job_id")
612
617
  self.class.transaction do
613
618
  job = nil
@@ -116,7 +116,7 @@ module Delayed
116
116
  # effectively balancing the load during queueing
117
117
  # overwritten in ActiveRecord::Job to use triggers to balance at run time
118
118
  def n_strand_options(strand_name, num_strands)
119
- strand_num = num_strands > 1 ? rand(num_strands) + 1 : 1
119
+ strand_num = (num_strands > 1) ? rand(num_strands) + 1 : 1
120
120
  strand_name += ":#{strand_num}" if strand_num > 1
121
121
  { strand: strand_name }
122
122
  end
@@ -217,7 +217,7 @@ module Delayed
217
217
  def failed?
218
218
  failed_at
219
219
  end
220
- alias failed failed?
220
+ alias_method :failed, :failed?
221
221
 
222
222
  def expired?
223
223
  expires_at && (self.class.db_time_now >= expires_at)
data/lib/delayed/cli.rb CHANGED
@@ -49,7 +49,7 @@ module Delayed
49
49
  daemon.daemonize!
50
50
  start
51
51
  when nil
52
- puts option_parser.to_s
52
+ puts option_parser.help
53
53
  else
54
54
  raise("Unknown command: #{command.inspect}")
55
55
  end
@@ -82,7 +82,8 @@ module Delayed
82
82
  opts.on("-c", "--config [CONFIG_PATH]", "Use alternate config file (default #{@options[:config_file]})") do |c|
83
83
  @options[:config_file] = c
84
84
  end
85
- opts.on("-p", "--pid [PID_PATH]",
85
+ opts.on("-p",
86
+ "--pid [PID_PATH]",
86
87
  "Use alternate folder for PID files (default #{@options[:pid_folder]})") do |p|
87
88
  @options[:pid_folder] = p
88
89
  end
@@ -46,7 +46,7 @@ module Delayed
46
46
  missing_callback(event) unless @callbacks.key?(event)
47
47
 
48
48
  unless EVENTS[event].size == args.size
49
- raise ArgumentError, "Callback #{event} expects #{EVENTS[event].size} parameter(s): #{EVENTS[event].join(', ')}"
49
+ raise ArgumentError, "Callback #{event} expects #{EVENTS[event].size} parameter(s): #{EVENTS[event].join(", ")}"
50
50
  end
51
51
 
52
52
  @callbacks[event].execute(*args, &block)
@@ -5,8 +5,8 @@ module Delayed
5
5
  def run
6
6
  if Rails.logger.respond_to?(:log_path)
7
7
  log_path = Rails.logger.log_path
8
- elsif Rails.logger.instance_variable_get("@logdev").try(:instance_variable_get, "@dev").try(:path)
9
- log_path = Rails.logger.instance_variable_get("@logdev").instance_variable_get("@dev").path
8
+ elsif Rails.logger.instance_variable_get(:@logdev).try(:instance_variable_get, "@dev").try(:path)
9
+ log_path = Rails.logger.instance_variable_get(:@logdev).instance_variable_get(:@dev).path
10
10
  else
11
11
  return
12
12
  end
@@ -19,7 +19,7 @@ module Delayed
19
19
  @object.protected_methods.exclude?(method) &&
20
20
  @object.private_methods.exclude?(method)
21
21
 
22
- sender_is_object = @sender == @object
22
+ sender_is_object = @sender.equal?(@object)
23
23
  sender_is_class = @sender.is_a?(@object.class)
24
24
 
25
25
  # even if the call is async, if the call is _going_ to generate an error, we make it synchronous
@@ -54,8 +54,10 @@ module Delayed
54
54
 
55
55
  if ::Delayed::Job != ::Delayed::Backend::ActiveRecord::Job || connection != ::Delayed::Job.connection
56
56
  connection.after_transaction_commit do
57
- ::Delayed::Job.enqueue(::Delayed::PerformableMethod.new(@object, method,
58
- args: args, kwargs: kwargs,
57
+ ::Delayed::Job.enqueue(::Delayed::PerformableMethod.new(@object,
58
+ method,
59
+ args: args,
60
+ kwargs: kwargs,
59
61
  on_failure: on_failure,
60
62
  on_permanent_failure: on_permanent_failure,
61
63
  sender: @sender),
@@ -65,7 +67,8 @@ module Delayed
65
67
  end
66
68
  end
67
69
 
68
- result = ::Delayed::Job.enqueue(::Delayed::PerformableMethod.new(@object, method,
70
+ result = ::Delayed::Job.enqueue(::Delayed::PerformableMethod.new(@object,
71
+ method,
69
72
  args: args,
70
73
  kwargs: kwargs,
71
74
  on_failure: on_failure,
@@ -21,6 +21,8 @@ module Delayed
21
21
  self.permanent_fail_cb = on_permanent_failure
22
22
  self.sender_is_object = sender.equal?(object)
23
23
  self.sender_is_class = sender.is_a?(object.class)
24
+ # bypass visibility checks (see MessageSending#__calculate_sender_for_delay)
25
+ self.sender_is_object = true if sender.nil?
24
26
  end
25
27
 
26
28
  def display_name
@@ -36,7 +38,7 @@ module Delayed
36
38
  kwargs = self.kwargs || {}
37
39
 
38
40
  # back-compat for jobs queued before we assigned these in initialize
39
- self.sender_is_object = sender == object if sender_is_object.nil?
41
+ self.sender_is_object = sender.equal?(object) if sender_is_object.nil?
40
42
  self.sender_is_class = sender.is_a?(object.class) if sender_is_class.nil?
41
43
 
42
44
  if sender_is_object || (sender_is_class && object.protected_methods.include?(method))
@@ -63,9 +65,9 @@ module Delayed
63
65
  def deep_de_ar_ize(arg)
64
66
  case arg
65
67
  when Hash
66
- "{#{arg.map { |k, v| "#{deep_de_ar_ize(k)} => #{deep_de_ar_ize(v)}" }.join(', ')}}"
68
+ "{#{arg.map { |k, v| "#{deep_de_ar_ize(k)} => #{deep_de_ar_ize(v)}" }.join(", ")}}"
67
69
  when Array
68
- "[#{arg.map { |a| deep_de_ar_ize(a) }.join(', ')}]"
70
+ "[#{arg.map { |a| deep_de_ar_ize(a) }.join(", ")}]"
69
71
  when ActiveRecord::Base
70
72
  "#{arg.class}.find(#{arg.id})"
71
73
  else
@@ -77,7 +79,7 @@ module Delayed
77
79
  obj_name = object.is_a?(ActiveRecord::Base) ? "#{object.class}.find(#{object.id}).#{method}" : display_name
78
80
  kgs = kwargs || {}
79
81
  kwargs_str = kgs.map { |(k, v)| ", #{k}: #{deep_de_ar_ize(v)}" }.join
80
- "#{obj_name}(#{args.map { |a| deep_de_ar_ize(a) }.join(', ')}#{kwargs_str})"
82
+ "#{obj_name}(#{args.map { |a| deep_de_ar_ize(a) }.join(", ")}#{kwargs_str})"
81
83
  end
82
84
  end
83
85
  end
@@ -83,7 +83,7 @@ module Delayed
83
83
  def tag
84
84
  "periodic: #{@name}"
85
85
  end
86
- alias display_name tag
86
+ alias_method :display_name, :tag
87
87
 
88
88
  def self.now
89
89
  Time.zone.now
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "3.1.8"
4
+ VERSION = "3.1.10"
5
5
  end
@@ -163,7 +163,7 @@ module Delayed
163
163
  forced_latency: forced_latency
164
164
  )
165
165
  logger.debug(
166
- "Fetched and locked #{response.values.flatten.size} new jobs for workers (#{response.keys.join(', ')})."
166
+ "Fetched and locked #{response.values.flatten.size} new jobs for workers (#{response.keys.join(", ")})."
167
167
  )
168
168
  response.each do |(worker_name, locked_jobs)|
169
169
  if worker_name == prefetch_owner
@@ -267,7 +267,7 @@ module Delayed
267
267
  end
268
268
 
269
269
  def prefetch_owner
270
- "prefetch:#{Socket.gethostname rescue 'X'}"
270
+ "prefetch:#{Socket.gethostname rescue "X"}"
271
271
  end
272
272
 
273
273
  def parent_exited?
@@ -9,9 +9,9 @@ module Delayed
9
9
  ALIVE_CHECK_LINUX = '[ -d "/proc/$WORKER_PID" ]'
10
10
  ALIVE_CHECK_MAC = "ps -p $WORKER_PID > /dev/null"
11
11
  ALIVE_CHECK = RUBY_PLATFORM.include?("darwin") ? ALIVE_CHECK_MAC : ALIVE_CHECK_LINUX
12
- SCRIPT_TEMPLATE = <<-BASH
13
- WORKER_PID="%<pid>d" # an example, filled from ruby when the check is created
14
- ORIGINAL_MTIME="%<mtime>s" # an example, filled from ruby when the check is created
12
+ SCRIPT_TEMPLATE = <<~SH
13
+ WORKER_PID="%{pid}" # an example, filled from ruby when the check is created
14
+ ORIGINAL_MTIME="%{mtime}" # an example, filled from ruby when the check is created
15
15
 
16
16
  if #{ALIVE_CHECK}; then
17
17
  CURRENT_MTIME=$(#{STAT})
@@ -26,7 +26,7 @@ module Delayed
26
26
  else
27
27
  exit 255 # The process is no more, trigger a "critical" state.
28
28
  fi
29
- BASH
29
+ SH
30
30
 
31
31
  def self.mtime(pid)
32
32
  if RUBY_PLATFORM.include?("darwin")
@@ -77,7 +77,7 @@ module Delayed
77
77
  end
78
78
 
79
79
  def name
80
- @name ||= "#{Socket.gethostname rescue 'X'}:#{id}"
80
+ @name ||= "#{Socket.gethostname rescue "X"}:#{id}"
81
81
  end
82
82
 
83
83
  def process_name=(new_name)
@@ -100,7 +100,7 @@ module Delayed
100
100
  def start
101
101
  logger.info "Starting worker"
102
102
  self.process_name =
103
- "start:#{Settings.worker_procname_prefix}#{@queue_name}:#{min_priority || 0}:#{max_priority || 'max'}"
103
+ "start:#{Settings.worker_procname_prefix}#{@queue_name}:#{min_priority || 0}:#{max_priority || "max"}"
104
104
  @self_pipe = IO.pipe
105
105
  work_queue.init
106
106
 
@@ -170,7 +170,7 @@ module Delayed
170
170
 
171
171
  self.class.lifecycle.run_callbacks(:loop, self) do
172
172
  self.process_name =
173
- "pop:#{Settings.worker_procname_prefix}#{@queue_name}:#{min_priority || 0}:#{max_priority || 'max'}"
173
+ "pop:#{Settings.worker_procname_prefix}#{@queue_name}:#{min_priority || 0}:#{max_priority || "max"}"
174
174
  job = self.class.lifecycle.run_callbacks(:pop, self) do
175
175
  work_queue.get_and_lock_next_available(name, config)
176
176
  end
@@ -196,7 +196,7 @@ module Delayed
196
196
  end
197
197
  else
198
198
  self.process_name =
199
- "wait:#{Settings.worker_procname_prefix}#{@queue_name}:#{min_priority || 0}:#{max_priority || 'max'}"
199
+ "wait:#{Settings.worker_procname_prefix}#{@queue_name}:#{min_priority || 0}:#{max_priority || "max"}"
200
200
  sleep(Settings.sleep_delay + (rand * Settings.sleep_delay_stagger)) unless exit?
201
201
  end
202
202
  end
@@ -220,7 +220,7 @@ module Delayed
220
220
  end
221
221
  job.destroy
222
222
  end
223
- logger.info("Completed #{log_job(job, :short)} #{format('%.0fms', (runtime * 1000))}")
223
+ logger.info("Completed #{log_job(job, :short)} #{format("%.0fms", (runtime * 1000))}")
224
224
  end
225
225
  rescue ::Delayed::RetriableError => e
226
226
  can_retry = job.attempts + 1 < job.inferred_max_attempts
@@ -279,7 +279,7 @@ module Delayed
279
279
  previous_tmpdir = ENV.fetch("TMPDIR", nil)
280
280
 
281
281
  self.class.running_job(job) do
282
- dir = Dir.mktmpdir("job-#{job.id}-#{name.gsub(/[^\w.]/, '.')}-")
282
+ dir = Dir.mktmpdir("job-#{job.id}-#{name.gsub(/[^\w.]/, ".")}-")
283
283
  begin
284
284
  ENV["TMPDIR"] = dir
285
285
  yield
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.8
4
+ version: 3.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cody Cutrer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2023-04-18 00:00:00.000000000 Z
13
+ date: 2023-05-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -285,33 +285,19 @@ dependencies:
285
285
  - !ruby/object:Gem::Version
286
286
  version: '3.10'
287
287
  - !ruby/object:Gem::Dependency
288
- name: rubocop
288
+ name: rubocop-inst
289
289
  requirement: !ruby/object:Gem::Requirement
290
290
  requirements:
291
291
  - - "~>"
292
292
  - !ruby/object:Gem::Version
293
- version: '1.19'
293
+ version: '1'
294
294
  type: :development
295
295
  prerelease: false
296
296
  version_requirements: !ruby/object:Gem::Requirement
297
297
  requirements:
298
298
  - - "~>"
299
299
  - !ruby/object:Gem::Version
300
- version: '1.19'
301
- - !ruby/object:Gem::Dependency
302
- name: rubocop-performance
303
- requirement: !ruby/object:Gem::Requirement
304
- requirements:
305
- - - "~>"
306
- - !ruby/object:Gem::Version
307
- version: 1.12.0
308
- type: :development
309
- prerelease: false
310
- version_requirements: !ruby/object:Gem::Requirement
311
- requirements:
312
- - - "~>"
313
- - !ruby/object:Gem::Version
314
- version: 1.12.0
300
+ version: '1'
315
301
  - !ruby/object:Gem::Dependency
316
302
  name: rubocop-rails
317
303
  requirement: !ruby/object:Gem::Requirement