app/models/good_job/execution.rb in good_job-3.27.4 vs app/models/good_job/execution.rb in good_job-3.28.0

- old
+ new

@@ -93,11 +93,11 @@ # Get executions that are not scheduled for a later time than now (i.e. jobs that # are not scheduled or scheduled for earlier than the current time). # @!method only_scheduled # @!scope class # @return [ActiveRecord::Relation] - scope :only_scheduled, -> { where(arel_table['scheduled_at'].lteq(Arel::Nodes::BindParam.new(ActiveModel::Attribute.with_cast_value("scheduled_at", Time.current, ActiveModel::Type::DateTime.new)))).or(where(scheduled_at: nil)) } + scope :only_scheduled, -> { where(arel_table['scheduled_at'].lteq(bind_value('scheduled_at', DateTime.current, ActiveRecord::Type::DateTime))).or(where(scheduled_at: nil)) } # Order executions by priority (highest priority first). # @!method priority_ordered # @!scope class # @return [ActiveRecord::Relation] @@ -159,11 +159,11 @@ # @!method finished(timestamp = nil) # @!scope class # @param timestamp (Float) # Get jobs that finished before this time (in epoch time). # @return [ActiveRecord::Relation] - scope :finished, ->(timestamp = nil) { timestamp ? where(arel_table['finished_at'].lteq(timestamp)) : where.not(finished_at: nil) } + scope :finished, ->(timestamp = nil) { timestamp ? where(arel_table['finished_at'].lteq(bind_value('finished_at', timestamp, ActiveRecord::Type::DateTime))) : where.not(finished_at: nil) } # Get Jobs that started but not finished yet. # @!method running # @!scope class # @return [ActiveRecord::Relation] @@ -288,15 +288,16 @@ # @return [Array<DateTime>] def self.next_scheduled_at(after: nil, limit: 100, now_limit: nil) query = advisory_unlocked.unfinished.schedule_ordered after ||= Time.current - after_query = query.where('scheduled_at > ?', after).or query.where(scheduled_at: nil).where('created_at > ?', after) + after_bind = bind_value('scheduled_at', after, ActiveRecord::Type::DateTime) + after_query = query.where(arel_table['scheduled_at'].gt(after_bind)).or query.where(scheduled_at: nil).where(arel_table['created_at'].gt(after_bind)) after_at = after_query.limit(limit).pluck(:scheduled_at, :created_at).map { |timestamps| timestamps.compact.first } if now_limit&.positive? - now_query = query.where('scheduled_at < ?', Time.current).or query.where(scheduled_at: nil) + now_query = query.where(arel_table['scheduled_at'].lt(bind_value('scheduled_at', Time.current, ActiveRecord::Type::DateTime))).or query.where(scheduled_at: nil) now_at = now_query.limit(now_limit).pluck(:scheduled_at, :created_at).map { |timestamps| timestamps.compact.first } end Array(now_at) + after_at end @@ -458,9 +459,10 @@ job_attributes[:error] = error_string job_attributes[:error_event] = result.error_event if self.class.error_event_migrated? if discrete_execution discrete_execution.error = error_string discrete_execution.error_event = result.error_event + discrete_execution.error_backtrace = job_error.backtrace if discrete_execution.class.backtrace_migrated? end else job_attributes[:error] = nil job_attributes[:error_event] = nil end