Module: SwitchmanInstJobs::Delayed::Backend::Base
- Defined in:
- lib/switchman_inst_jobs/delayed/backend/base.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #current_shard ⇒ Object
- #current_shard=(shard) ⇒ Object
- #deserialize(source) ⇒ Object
- #invoke_job ⇒ Object
Class Method Details
.prepended(base) ⇒ Object
62 63 64 65 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 62 def self.prepended(base) base.singleton_class.prepend(ClassMethods) base.shard_category = :delayed_jobs if base.name == 'Delayed::Backend::ActiveRecord::Job' end |
Instance Method Details
#current_shard ⇒ Object
67 68 69 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 67 def current_shard @current_shard ||= ::Switchman::Shard.lookup(shard_id) end |
#current_shard=(shard) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 71 def current_shard=(shard) @current_shard = nil self.shard_id = shard.id self.shard_id = nil if shard.is_a?(::Switchman::DefaultShard) # If jobs are held for a shard, enqueue new ones as held as well return unless shard.jobs_held self.locked_by = ::Delayed::Backend::Base::ON_HOLD_LOCKED_BY self.locked_at = ::Delayed::Job.db_time_now self.attempts = ::Delayed::Backend::Base::ON_HOLD_COUNT end |
#deserialize(source) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 87 def deserialize(source) raise ShardNotFoundError, shard_id unless current_shard current_shard.activate { super } rescue ::Switchman::ConnectionError, PG::ConnectionBad, PG::UndefinedTable # likely a missing shard with a stale cache current_shard.send(:clear_cache) ::Switchman::Shard.clear_cache raise ShardNotFoundError, shard_id unless ::Switchman::Shard.exists?(id: shard_id) raise end |
#invoke_job ⇒ Object
83 84 85 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 83 def invoke_job current_shard.activate { super } end |