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
77 78 79 |
# File 'lib/crono_trigger/schedulable.rb', line 77 def crono_trigger_column_name(name) ["#{name}_column_name".to_sym].try(:to_s) || name.to_s end |
#crono_trigger_unlock_all! ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/crono_trigger/schedulable.rb', line 85 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
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/crono_trigger/schedulable.rb', line 63 def executables_with_lock(limit: CronoTrigger.config.executor_thread * 3 || 100) records = nil transaction do records = executables(limit: limit).lock.to_a unless records.empty? where(id: records).update_all( crono_trigger_column_name(:execute_lock) => Time.current.to_i, crono_trigger_column_name(:locked_by) => CronoTrigger.config.worker_id ) end records end end |
#execute_lock_timeout ⇒ Object
81 82 83 |
# File 'lib/crono_trigger/schedulable.rb', line 81 def execute_lock_timeout ([:execute_lock_timeout] || DEFAULT_EXECUTE_LOCK_TIMEOUT) end |