switchman-inst-jobs 1.5.0 → 3.0.0

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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20101216224513_create_delayed_jobs.rb +42 -0
  3. data/db/migrate/20110208031356_add_delayed_jobs_tag.rb +14 -0
  4. data/db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb +13 -0
  5. data/db/migrate/20110516225834_add_delayed_jobs_strand.rb +14 -0
  6. data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +26 -0
  7. data/db/migrate/20110610213249_optimize_delayed_jobs.rb +40 -0
  8. data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +52 -0
  9. data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +31 -0
  10. data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +15 -0
  11. data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +80 -0
  12. data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +15 -0
  13. data/db/migrate/20120608191051_add_jobs_run_at_index.rb +15 -0
  14. data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +13 -0
  15. data/db/migrate/20140505215131_add_failed_jobs_original_job_id.rb +13 -0
  16. data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +12 -0
  17. data/db/migrate/20140505223637_drop_failed_jobs_original_id.rb +13 -0
  18. data/db/migrate/20140512213941_add_source_to_jobs.rb +15 -0
  19. data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +70 -0
  20. data/db/migrate/20151123210429_add_expires_at_to_jobs.rb +15 -0
  21. data/db/migrate/20151210162949_improve_max_concurrent.rb +50 -0
  22. data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +39 -0
  23. data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +95 -0
  24. data/db/migrate/20190726154743_make_critical_columns_not_null.rb +15 -0
  25. data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +25 -0
  26. data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +94 -0
  27. data/db/migrate/20200825011002_add_strand_order_override.rb +126 -0
  28. data/lib/switchman_inst_jobs.rb +3 -3
  29. data/lib/switchman_inst_jobs/active_record/migration.rb +10 -0
  30. data/lib/switchman_inst_jobs/delayed/backend/base.rb +9 -9
  31. data/lib/switchman_inst_jobs/delayed/message_sending.rb +2 -2
  32. data/lib/switchman_inst_jobs/delayed/worker/health_check.rb +1 -3
  33. data/lib/switchman_inst_jobs/engine.rb +2 -2
  34. data/lib/switchman_inst_jobs/{shackles.rb → guard_rail.rb} +1 -1
  35. data/lib/switchman_inst_jobs/jobs_migrator.rb +9 -7
  36. data/lib/switchman_inst_jobs/switchman/default_shard.rb +4 -0
  37. data/lib/switchman_inst_jobs/version.rb +1 -1
  38. metadata +45 -32
  39. data/db/migrate/20180628153808_set_search_paths_on_functions.rb +0 -15
@@ -25,8 +25,8 @@ module SwitchmanInstJobs
25
25
  ::Object.include Delayed::MessageSending
26
26
  end
27
27
 
28
- def self.initialize_shackles
29
- ::Shackles.singleton_class.prepend Shackles::ClassMethods
28
+ def self.initialize_guard_rail
29
+ ::GuardRail.singleton_class.prepend GuardRail::ClassMethods
30
30
  end
31
31
 
32
32
  def self.initialize_switchman
@@ -44,9 +44,9 @@ require 'switchman_inst_jobs/delayed/pool'
44
44
  require 'switchman_inst_jobs/delayed/worker'
45
45
  require 'switchman_inst_jobs/delayed/worker/health_check'
46
46
  require 'switchman_inst_jobs/engine'
47
+ require 'switchman_inst_jobs/guard_rail'
47
48
  require 'switchman_inst_jobs/jobs_migrator'
48
49
  require 'switchman_inst_jobs/new_relic'
49
- require 'switchman_inst_jobs/shackles'
50
50
  require 'switchman_inst_jobs/switchman/database_server'
51
51
  require 'switchman_inst_jobs/switchman/default_shard'
52
52
  require 'switchman_inst_jobs/switchman/shard'
@@ -17,6 +17,16 @@ module SwitchmanInstJobs
17
17
  ensure
18
18
  ::ActiveRecord::Migration.open_migrations -= 1
19
19
  end
20
+
21
+ def copy(destination, sources, options = {})
22
+ if sources.delete('delayed_engine')
23
+ # rubocop:disable Rails/Output
24
+ puts 'NOTE: Not installing delayed_engine migrations in an application using switchman-inst-jobs'
25
+ puts '(use rake switchman_inst_jobs:install:migrations instead)'
26
+ # rubocop:enable Rails/Output
27
+ end
28
+ super
29
+ end
20
30
  end
21
31
  end
22
32
  end
@@ -12,13 +12,13 @@ module SwitchmanInstJobs
12
12
  module Backend
13
13
  module Base
14
14
  module ClassMethods
15
- def enqueue(object, options = {})
15
+ def enqueue(object, **options)
16
16
  ::Switchman::Shard.periodic_clear_shard_cache
17
17
  current_shard = ::Switchman::Shard.current
18
18
  enqueue_options = options.merge(
19
19
  current_shard: current_shard
20
20
  )
21
- enqueue_job = -> { ::Shackles.activate(:master) { super(object, enqueue_options) } }
21
+ enqueue_job = -> { ::GuardRail.activate(:master) { super(object, **enqueue_options) } }
22
22
 
23
23
  # Another dj shard must be currently manually activated, so just use that
24
24
  # In general this will only happen in unusual circumstances like tests
@@ -29,15 +29,15 @@ module SwitchmanInstJobs
29
29
  else
30
30
  ::Switchman::Shard.default.activate do
31
31
  current_shard = ::Switchman::Shard.lookup(current_shard.id)
32
- current_job_shard = current_shard.delayed_jobs_shard
32
+ end
33
+ current_job_shard = current_shard.delayed_jobs_shard
33
34
 
34
- if (options[:singleton] || options[:strand]) && current_shard.block_stranded
35
- enqueue_options[:next_in_strand] = false
36
- end
35
+ if (options[:singleton] || options[:strand]) && current_shard.block_stranded
36
+ enqueue_options[:next_in_strand] = false
37
+ end
37
38
 
38
- current_job_shard.activate(:delayed_jobs) do
39
- enqueue_job.call
40
- end
39
+ current_job_shard.activate(:delayed_jobs) do
40
+ enqueue_job.call
41
41
  end
42
42
  end
43
43
  end
@@ -1,8 +1,8 @@
1
1
  module SwitchmanInstJobs
2
2
  module Delayed
3
3
  module MessageSending
4
- def send_later_enqueue_args(method, _enqueue_args = {}, *args)
5
- return send(method, *args) if ::Switchman::DatabaseServer.creating_new_shard
4
+ def delay(**enqueue_args)
5
+ return self if ::Switchman::DatabaseServer.creating_new_shard
6
6
 
7
7
  super
8
8
  end
@@ -32,9 +32,7 @@ module SwitchmanInstJobs
32
32
  singleton = <<~SINGLETON
33
33
  periodic: Delayed::Worker::HealthCheck.reschedule_abandoned_jobs:#{shard.id}
34
34
  SINGLETON
35
- send_later_enqueue_args(
36
- :reschedule_abandoned_jobs, { singleton: singleton }, call_super: shard
37
- )
35
+ delay(singleton: singleton).reschedule_abandoned_jobs(call_super: shard)
38
36
  end
39
37
  end
40
38
  end
@@ -34,8 +34,8 @@ module SwitchmanInstJobs
34
34
  end
35
35
  end
36
36
 
37
- initializer 'sharding.shackles', after: 'switchman.extend_shackles' do
38
- SwitchmanInstJobs.initialize_shackles
37
+ initializer 'sharding.guard_rail', after: 'switchman.extend_guard_rail' do
38
+ SwitchmanInstJobs.initialize_guard_rail
39
39
  end
40
40
 
41
41
  initializer 'sharding.switchman' do
@@ -1,5 +1,5 @@
1
1
  module SwitchmanInstJobs
2
- module Shackles
2
+ module GuardRail
3
3
  module ClassMethods
4
4
  def activate(env, &block)
5
5
  if ::ActiveRecord::Migration.open_migrations.positive?
@@ -95,7 +95,7 @@ module SwitchmanInstJobs
95
95
  first = this_strand_scope.where('locked_by IS NOT NULL').next_in_strand_order.lock.first
96
96
  if first
97
97
  first_job = ::Delayed::Job.create!(strand: strand, next_in_strand: false)
98
- first_job.payload_object = ::Delayed::PerformableMethod.new(Kernel, :sleep, [0])
98
+ first_job.payload_object = ::Delayed::PerformableMethod.new(Kernel, :sleep, args: [0])
99
99
  first_job.queue = first.queue
100
100
  first_job.tag = 'Kernel.sleep'
101
101
  first_job.source = 'JobsMigrator::StrandBlocker'
@@ -183,12 +183,14 @@ module SwitchmanInstJobs
183
183
  # Adapted from get_and_lock_next_available in delayed/backend/active_record.rb
184
184
  target_jobs = scope.limit(1000).lock('FOR UPDATE SKIP LOCKED')
185
185
 
186
- query = "WITH limited_jobs AS (#{target_jobs.to_sql}) " \
187
- "UPDATE #{::Delayed::Job.quoted_table_name} " \
188
- "SET locked_by = #{::Delayed::Job.connection.quote(::Delayed::Backend::Base::ON_HOLD_LOCKED_BY)}, " \
189
- "locked_at = #{::Delayed::Job.connection.quote(::Delayed::Job.db_time_now)} "\
190
- "FROM limited_jobs WHERE limited_jobs.id=#{::Delayed::Job.quoted_table_name}.id " \
191
- "RETURNING #{::Delayed::Job.quoted_table_name}.*"
186
+ query = source_shard.activate(:delayed_jobs) do
187
+ "WITH limited_jobs AS (#{target_jobs.to_sql}) " \
188
+ "UPDATE #{::Delayed::Job.quoted_table_name} " \
189
+ "SET locked_by = #{::Delayed::Job.connection.quote(::Delayed::Backend::Base::ON_HOLD_LOCKED_BY)}, " \
190
+ "locked_at = #{::Delayed::Job.connection.quote(::Delayed::Job.db_time_now)} "\
191
+ "FROM limited_jobs WHERE limited_jobs.id=#{::Delayed::Job.quoted_table_name}.id " \
192
+ "RETURNING #{::Delayed::Job.quoted_table_name}.*"
193
+ end
192
194
 
193
195
  jobs = source_shard.activate(:delayed_jobs) { ::Delayed::Job.find_by_sql(query) }
194
196
  new_jobs = jobs.map do |job|
@@ -8,6 +8,10 @@ module SwitchmanInstJobs
8
8
  def jobs_held
9
9
  false
10
10
  end
11
+
12
+ def block_stranded
13
+ false
14
+ end
11
15
  end
12
16
  end
13
17
  end
@@ -1,3 +1,3 @@
1
1
  module SwitchmanInstJobs
2
- VERSION = '1.5.0'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switchman-inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Petty
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inst-jobs
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0.16'
20
- - - "<"
17
+ - - "~>"
21
18
  - !ruby/object:Gem::Version
22
- version: '0.17'
19
+ version: '1.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: '0.16'
30
- - - "<"
24
+ - - "~>"
31
25
  - !ruby/object:Gem::Version
32
- version: '0.17'
26
+ version: '1.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: parallel
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,22 +62,16 @@ dependencies:
68
62
  name: switchman
69
63
  requirement: !ruby/object:Gem::Requirement
70
64
  requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: '1.14'
74
- - - "<"
65
+ - - "~>"
75
66
  - !ruby/object:Gem::Version
76
- version: '1.16'
67
+ version: '2.0'
77
68
  type: :runtime
78
69
  prerelease: false
79
70
  version_requirements: !ruby/object:Gem::Requirement
80
71
  requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '1.14'
84
- - - "<"
72
+ - - "~>"
85
73
  - !ruby/object:Gem::Version
86
- version: '1.16'
74
+ version: '2.0'
87
75
  - !ruby/object:Gem::Dependency
88
76
  name: bundler
89
77
  requirement: !ruby/object:Gem::Requirement
@@ -174,14 +162,14 @@ dependencies:
174
162
  requirements:
175
163
  - - "~>"
176
164
  - !ruby/object:Gem::Version
177
- version: '12'
165
+ version: '13'
178
166
  type: :development
179
167
  prerelease: false
180
168
  version_requirements: !ruby/object:Gem::Requirement
181
169
  requirements:
182
170
  - - "~>"
183
171
  - !ruby/object:Gem::Version
184
- version: '12'
172
+ version: '13'
185
173
  - !ruby/object:Gem::Dependency
186
174
  name: rspec
187
175
  requirement: !ruby/object:Gem::Requirement
@@ -266,17 +254,42 @@ dependencies:
266
254
  - - "~>"
267
255
  - !ruby/object:Gem::Version
268
256
  version: '1.4'
269
- description:
257
+ description:
270
258
  email:
271
259
  - bpetty@instructure.com
272
260
  executables: []
273
261
  extensions: []
274
262
  extra_rdoc_files: []
275
263
  files:
264
+ - db/migrate/20101216224513_create_delayed_jobs.rb
265
+ - db/migrate/20110208031356_add_delayed_jobs_tag.rb
266
+ - db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb
267
+ - db/migrate/20110516225834_add_delayed_jobs_strand.rb
268
+ - db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb
269
+ - db/migrate/20110610213249_optimize_delayed_jobs.rb
270
+ - db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb
271
+ - db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb
272
+ - db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb
273
+ - db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb
274
+ - db/migrate/20120607181141_index_jobs_on_locked_by.rb
275
+ - db/migrate/20120608191051_add_jobs_run_at_index.rb
276
+ - db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb
277
+ - db/migrate/20140505215131_add_failed_jobs_original_job_id.rb
278
+ - db/migrate/20140505215510_copy_failed_jobs_original_id.rb
279
+ - db/migrate/20140505223637_drop_failed_jobs_original_id.rb
280
+ - db/migrate/20140512213941_add_source_to_jobs.rb
281
+ - db/migrate/20150807133223_add_max_concurrent_to_jobs.rb
282
+ - db/migrate/20151123210429_add_expires_at_to_jobs.rb
283
+ - db/migrate/20151210162949_improve_max_concurrent.rb
284
+ - db/migrate/20161206323555_add_back_default_string_limits_jobs.rb
276
285
  - db/migrate/20170308045400_add_shard_id_to_delayed_jobs.rb
277
- - db/migrate/20180628153808_set_search_paths_on_functions.rb
286
+ - db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb
287
+ - db/migrate/20190726154743_make_critical_columns_not_null.rb
288
+ - db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb
278
289
  - db/migrate/20200818130101_add_on_hold_to_switchman_shards.rb
279
290
  - db/migrate/20200822014259_add_block_stranded_to_switchman_shards.rb
291
+ - db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb
292
+ - db/migrate/20200825011002_add_strand_order_override.rb
280
293
  - lib/switchman-inst-jobs.rb
281
294
  - lib/switchman_inst_jobs.rb
282
295
  - lib/switchman_inst_jobs/active_record/connection_adapters/postgresql_adapter.rb
@@ -287,9 +300,9 @@ files:
287
300
  - lib/switchman_inst_jobs/delayed/worker.rb
288
301
  - lib/switchman_inst_jobs/delayed/worker/health_check.rb
289
302
  - lib/switchman_inst_jobs/engine.rb
303
+ - lib/switchman_inst_jobs/guard_rail.rb
290
304
  - lib/switchman_inst_jobs/jobs_migrator.rb
291
305
  - lib/switchman_inst_jobs/new_relic.rb
292
- - lib/switchman_inst_jobs/shackles.rb
293
306
  - lib/switchman_inst_jobs/switchman/database_server.rb
294
307
  - lib/switchman_inst_jobs/switchman/default_shard.rb
295
308
  - lib/switchman_inst_jobs/switchman/shard.rb
@@ -300,7 +313,7 @@ homepage: https://github.com/instructure/switchman-inst-jobs
300
313
  licenses:
301
314
  - MIT
302
315
  metadata: {}
303
- post_install_message:
316
+ post_install_message:
304
317
  rdoc_options: []
305
318
  require_paths:
306
319
  - lib
@@ -308,15 +321,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
308
321
  requirements:
309
322
  - - ">="
310
323
  - !ruby/object:Gem::Version
311
- version: '2.4'
324
+ version: '2.5'
312
325
  required_rubygems_version: !ruby/object:Gem::Requirement
313
326
  requirements:
314
327
  - - ">="
315
328
  - !ruby/object:Gem::Version
316
329
  version: '0'
317
330
  requirements: []
318
- rubygems_version: 3.0.3
319
- signing_key:
331
+ rubygems_version: 3.1.4
332
+ signing_key:
320
333
  specification_version: 4
321
334
  summary: Switchman and Instructure Jobs compatibility gem.
322
335
  test_files: []
@@ -1,15 +0,0 @@
1
- class SetSearchPathsOnFunctions < ActiveRecord::Migration[4.2]
2
- disable_ddl_transaction!
3
-
4
- def up
5
- set_search_path('delayed_jobs_after_delete_row_tr_fn', '()')
6
- set_search_path('delayed_jobs_before_insert_row_tr_fn', '()')
7
- set_search_path('half_md5_as_bigint', '(varchar)')
8
- end
9
-
10
- def down
11
- set_search_path('delayed_jobs_after_delete_row_tr_fn', '()', 'DEFAULT')
12
- set_search_path('delayed_jobs_before_insert_row_tr_fn', '()', 'DEFAULT')
13
- set_search_path('half_md5_as_bigint', '(varchar)', 'DEFAULT')
14
- end
15
- end