Module: SwitchmanInstJobs::Switchman::Shard

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

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ Object



6
7
8
# File 'lib/switchman_inst_jobs/switchman/shard.rb', line 6

def self.prepended(base)
  base.singleton_class.prepend(ClassMethods)
end

Instance Method Details

#clear_cacheObject



10
11
12
# File 'lib/switchman_inst_jobs/switchman/shard.rb', line 10

def clear_cache
  self.class.connection.after_transaction_commit { super }
end

#delayed_jobs_shardObject



14
15
16
17
18
19
20
# File 'lib/switchman_inst_jobs/switchman/shard.rb', line 14

def delayed_jobs_shard
  if read_attribute(:delayed_jobs_shard_id)
    shard = ::Switchman::Shard.lookup(delayed_jobs_shard_id)
    return shard if shard
  end
  @delayed_jobs_shard ||= database_server&.delayed_jobs_shard(self)
end

#hold_jobs!(wait: false) ⇒ Object

Adapted from hold/unhold methods in base delayed jobs base Wait is required to be able to safely move jobs



24
25
26
# File 'lib/switchman_inst_jobs/switchman/shard.rb', line 24

def hold_jobs!(wait: false)
  ::Switchman::Shard.where(id: self).hold_jobs!(wait:)
end

#unhold_jobs!Object



28
29
30
# File 'lib/switchman_inst_jobs/switchman/shard.rb', line 28

def unhold_jobs!
  ::Switchman::Shard.where(id: self).unhold_jobs!
end