Module: SwitchmanInstJobs::Switchman::DatabaseServer

Defined in:
lib/switchman_inst_jobs/switchman/database_server.rb

Instance Method Summary collapse

Instance Method Details

#delayed_jobs_shard(shard = nil) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/switchman_inst_jobs/switchman/database_server.rb', line 4

def delayed_jobs_shard(shard = nil)
  return shard if config[:delayed_jobs_shard] == 'self'

  dj_shard =
    config[:delayed_jobs_shard] &&
    ::Switchman::Shard.lookup(config[:delayed_jobs_shard])
  # have to avoid recursion for the default shard asking for the default
  # shard's delayed_jobs_shard
  if shard&.default?
    # first look for any shard that behaves like a jobs shard
    dj_shard ||= ::Switchman::Shard.delayed_jobs_shards.find(&:database_server)
    # we're really truly out of options, use the default shard itself
    dj_shard ||= shard
  end
  dj_shard ||= SwitchmanInstJobs.delayed_jobs_shard_fallback&.call(self, shard)
  dj_shard || ::Switchman::Shard.default.delayed_jobs_shard
end