Sha256: ed0f9027fb4af1645c2f5ff015878ddbb5ed963e689e1936309eeb3898ef6d24
Contents?: true
Size: 1.73 KB
Versions: 3
Compression:
Stored size: 1.73 KB
Contents
class Transactor < ActiveRecord::Base belongs_to :worker include AASM aasm :column => :status do state :sleeping, :initial => true state :running, :before_enter => :start_worker, :after_enter => :fail event :run do transitions :to => :running, :from => :sleeping end end private def start_worker worker.update_attribute(:status, 'running') end def fail raise StandardError.new('failed on purpose') end end class NoLockTransactor < ActiveRecord::Base belongs_to :worker include AASM aasm :column => :status do state :sleeping, :initial => true state :running event :run do transitions :to => :running, :from => :sleeping end end end class LockTransactor < ActiveRecord::Base belongs_to :worker include AASM aasm :column => :status, requires_lock: true do state :sleeping, :initial => true state :running event :run do transitions :to => :running, :from => :sleeping end end end class LockNoWaitTransactor < ActiveRecord::Base belongs_to :worker include AASM aasm :column => :status, requires_lock: 'FOR UPDATE NOWAIT' do state :sleeping, :initial => true state :running event :run do transitions :to => :running, :from => :sleeping end end end class MultipleTransactor < ActiveRecord::Base belongs_to :worker include AASM aasm :left, :column => :status do state :sleeping, :initial => true state :running, :before_enter => :start_worker, :after_enter => :fail event :run do transitions :to => :running, :from => :sleeping end end private def start_worker worker.update_attribute(:status, 'running') end def fail raise StandardError.new('failed on purpose') end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
aasm-4.12.2 | spec/models/active_record/transactor.rb |
aasm-4.12.1 | spec/models/active_record/transactor.rb |
aasm-4.12.0 | spec/models/active_record/transactor.rb |