Sha256: 7f88c7f7f2e0e0a090e623785f47f2a051f7373ae9e5f313e4f7c104ebb782ba
Contents?: true
Size: 803 Bytes
Versions: 14
Compression:
Stored size: 803 Bytes
Contents
class QueuedTask < ApplicationRecord validates :klass, presence: true serialize :data, Hash scope :locked, -> { where(locked: true) } scope :not_locked, -> { where('locked = 0 OR locked IS NULL') } def lock! update_attribute :locked, true end def unlock! update_attribute :locked, false end def run! klass.constantize.new(data).run! end def self.queue(klass, data) create!(klass: klass, data: data) end def self.queue_unless_already_queued(klass, data) if where(klass: klass.to_s).where('data = ?', data.to_yaml).empty? self.queue(klass.to_s, data) end end def dequeue! destroy end def process! lock! begin run! dequeue! rescue raise ensure unlock! unless destroyed? end end end
Version data entries
14 entries across 14 versions & 1 rubygems