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 || 100) ⇒ Object
- #execute_lock_timeout ⇒ Object
Instance Method Details
#crono_trigger_column_name(name) ⇒ Object
81 82 83 |
# File 'lib/crono_trigger/schedulable.rb', line 81 def crono_trigger_column_name(name) ["#{name}_column_name".to_sym].try(:to_s) || name.to_s end |
#crono_trigger_unlock_all! ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/crono_trigger/schedulable.rb', line 89 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 || 100) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/crono_trigger/schedulable.rb', line 66 def executables_with_lock(limit: CronoTrigger.config.executor_thread * 3 || 100) ids = executables(limit: limit).pluck(:id) 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 end |
#execute_lock_timeout ⇒ Object
85 86 87 |
# File 'lib/crono_trigger/schedulable.rb', line 85 def execute_lock_timeout ([:execute_lock_timeout] || DEFAULT_EXECUTE_LOCK_TIMEOUT) end |