Module: CronoTrigger::Schedulable::ClassMethods
- Defined in:
- lib/crono_trigger/schedulable.rb
Instance Method Summary collapse
- #crono_trigger_column_name(name) ⇒ Object
- #crono_trigger_unlock_all! ⇒ Object
- #executables_with_lock(limit: CronoTrigger.config.executor_thread * 3) ⇒ Object
- #execute_lock_timeout ⇒ Object
Instance Method Details
#crono_trigger_column_name(name) ⇒ Object
82 83 84 |
# File 'lib/crono_trigger/schedulable.rb', line 82 def crono_trigger_column_name(name) ["#{name}_column_name".to_sym].try(:to_s) || name.to_s end |
#crono_trigger_unlock_all! ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/crono_trigger/schedulable.rb', line 90 def crono_trigger_unlock_all! wheres = all.where_values_hash if wheres.empty? raise NoRestrictedUnlockError, "Need `where` filter at least one, because this method is danger" else update_all( crono_trigger_column_name(:execute_lock) => 0, crono_trigger_column_name(:locked_by) => nil, ) end end |
#executables_with_lock(limit: CronoTrigger.config.executor_thread * 3) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/crono_trigger/schedulable.rb', line 66 def executables_with_lock(limit: CronoTrigger.config.executor_thread * 3) ids = executables(limit: limit).pluck(:id) maybe_has_next = !ids.empty? records = [] ids.each do |id| transaction do r = all.lock.find(id) unless r.locking? r.crono_trigger_lock! records << r end end end [records, maybe_has_next] end |
#execute_lock_timeout ⇒ Object
86 87 88 |
# File 'lib/crono_trigger/schedulable.rb', line 86 def execute_lock_timeout ([:execute_lock_timeout] || DEFAULT_EXECUTE_LOCK_TIMEOUT) end |