Module: SwitchmanInstJobs::Delayed::Backend::Base::ClassMethods
- Defined in:
- lib/switchman_inst_jobs/delayed/backend/base.rb
Instance Method Summary collapse
- #configured_shard_ids ⇒ Object
- #enqueue(object, **options) ⇒ Object
- #processes_locked_locally ⇒ Object
Instance Method Details
#configured_shard_ids ⇒ Object
49 50 51 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 49 def configured_shard_ids ::SwitchmanInstJobs::Delayed::Settings.configured_shard_ids end |
#enqueue(object, **options) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 18 def enqueue(object, **) ::Switchman::Shard.periodic_clear_shard_cache current_shard = [:current_shard] || ::Switchman::Shard.current = .merge( current_shard: current_shard ) enqueue_job = -> { ::GuardRail.activate(:primary) { super(object, **) } } # Another dj shard must be currently manually activated, so just use that # In general this will only happen in unusual circumstances like tests # also if migrations are running, always use the current shard's job shard if ::ActiveRecord::Migration.open_migrations.zero? && current_shard.delayed_jobs_shard != ::Switchman::Shard.current(::Delayed::Backend::ActiveRecord::AbstractJob) enqueue_job.call else current_shard = ::Switchman::Shard.lookup(current_shard.id) current_job_shard = current_shard.delayed_jobs_shard if ([:singleton] || [:strand]) && current_shard.block_stranded [:next_in_strand] = false end current_shard.activate do current_job_shard.activate(::Delayed::Backend::ActiveRecord::AbstractJob) do enqueue_job.call end end end end |
#processes_locked_locally ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 53 def processes_locked_locally shard_ids = configured_shard_ids if shard_ids.any? shards = shard_ids.map { |shard_id| ::Delayed::Worker.shard(shard_id) } ::Switchman::Shard.with_each_shard(shards, [::Delayed::Backend::ActiveRecord::AbstractJob]) do super end else super end end |