lib/crono_trigger/schedulable.rb in crono_trigger-0.6.2 vs lib/crono_trigger/schedulable.rb in crono_trigger-0.6.3
- old
+ new
@@ -32,11 +32,11 @@
has_many :crono_trigger_executions, class_name: "CronoTrigger::Models::Execution", as: :schedule, inverse_of: :schedule
define_model_callbacks :execute, :retry
- scope :executables, ->(from: Time.current, limit: CronoTrigger.config.executor_thread * 3 || 100, including_locked: false) do
+ scope :executables, ->(from: Time.current, limit: CronoTrigger.config.executor_thread * 3, including_locked: false) do
t = arel_table
rel = where(t[crono_trigger_column_name(:next_execute_at)].lteq(from))
rel = rel.where(t[crono_trigger_column_name(:execute_lock)].lt(from.to_i - execute_lock_timeout)) unless including_locked
@@ -61,22 +61,23 @@
validate :validate_cron_format
end
module ClassMethods
- def executables_with_lock(limit: CronoTrigger.config.executor_thread * 3 || 100)
+ 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
+ [records, maybe_has_next]
end
def crono_trigger_column_name(name)
crono_trigger_options["#{name}_column_name".to_sym].try(:to_s) || name.to_s
end