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
63 64 65 66 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 63 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
68 69 70 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 68 def current_shard @current_shard ||= ::Switchman::Shard.lookup(shard_id) end |
#current_shard=(shard) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 72 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
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 88 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
84 85 86 |
# File 'lib/switchman_inst_jobs/delayed/backend/base.rb', line 84 def invoke_job current_shard.activate { super } end |