Module: SmsOnRails::LockableRecord::ClassMethods
- Defined in:
- lib/sms_on_rails/activerecord_extensions/lockable_record.rb
Instance Method Summary collapse
- #delete_stale_records ⇒ Object
- #lockable_record(options = {}) ⇒ Object
- #locrec_columns ⇒ Object
- #locrec_status ⇒ Object
- #recover_stale_records ⇒ Object
- #stale_record_conditions ⇒ Object
Instance Method Details
#delete_stale_records ⇒ Object
168 169 170 |
# File 'lib/sms_on_rails/activerecord_extensions/lockable_record.rb', line 168 def delete_stale_records delete_all stale_record_conditions end |
#lockable_record(options = {}) ⇒ Object
150 151 152 153 154 155 156 157 |
# File 'lib/sms_on_rails/activerecord_extensions/lockable_record.rb', line 150 def lockable_record(={}) self. = ActiveRecord::Base..merge() [:columns, :status].each do |method| if [method] self.[method] = ActiveRecord::Base.[method].merge([method]) end end end |
#locrec_columns ⇒ Object
159 |
# File 'lib/sms_on_rails/activerecord_extensions/lockable_record.rb', line 159 def locrec_columns; [:columns]; end |
#locrec_status ⇒ Object
160 |
# File 'lib/sms_on_rails/activerecord_extensions/lockable_record.rb', line 160 def locrec_status; [:status]; end |
#recover_stale_records ⇒ Object
162 163 164 165 |
# File 'lib/sms_on_rails/activerecord_extensions/lockable_record.rb', line 162 def recover_stale_records update_all(["#{locrec_columns[:status]} = ?", locrec_status[:not_processed]], stale_record_conditions) end |
#stale_record_conditions ⇒ Object
172 173 174 175 176 177 178 179 |
# File 'lib/sms_on_rails/activerecord_extensions/lockable_record.rb', line 172 def stale_record_conditions query = [] query << "#{locrec_columns[:status]} = :status" query << "#{locrec_columns[:processed_on]} < now() - interval :min minute" map = {:status => locrec_status[:processing], :min => [:recover_stalled_minutes]} [query.join(' AND '), map] end |