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
48
49
|
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 20
def enqueue(object, **options)
::Switchman::Shard.periodic_clear_shard_cache
current_shard = options[:current_shard] || ::Switchman::Shard.current
enqueue_options = options.merge(
current_shard:
)
enqueue_job = -> { ::GuardRail.activate(:primary) { super(object, **enqueue_options) } }
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 (options[:singleton] || options[:strand]) && current_shard.block_stranded
enqueue_options[: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
|