module Fleiss::Backend::ActiveRecord::Concern
Public Instance Methods
finish(owner, now: Time.zone.now)
click to toggle source
Marks a job as finished. @param [String] owner @return [Boolean] true if successful.
# File lib/fleiss/backend/active_record/concern.rb, line 84 def finish(owner, now: Time.zone.now) with_isolation do self.class .in_progress(owner) .where(id: id) .update_all(finished_at: now) end == 1 rescue ::ActiveRecord::SerializationFailure false end
job_data()
click to toggle source
@return [Hash] serialized job data
# File lib/fleiss/backend/active_record/concern.rb, line 59 def job_data @job_data ||= JSON.parse(payload) end
job_id()
click to toggle source
@return [String] the ActiveJob
ID
# File lib/fleiss/backend/active_record/concern.rb, line 64 def job_id job_data['job_id'] end
reschedule(owner, now: Time.zone.now)
click to toggle source
Reschedules the job to run again.
# File lib/fleiss/backend/active_record/concern.rb, line 96 def reschedule(owner, now: Time.zone.now) with_isolation do self.class .in_progress(owner) .where(id: id) .update_all(started_at: nil, owner: nil, scheduled_at: now) end == 1 rescue ::ActiveRecord::SerializationFailure false end
start(owner, now: Time.zone.now)
click to toggle source
Acquires a lock and starts the job. @param [String] owner @return [Boolean] true if job was started.
# File lib/fleiss/backend/active_record/concern.rb, line 71 def start(owner, now: Time.zone.now) with_isolation do self.class.pending(now) .where(id: id) .update_all(started_at: now, owner: owner) end == 1 rescue ::ActiveRecord::SerializationFailure false end
Private Instance Methods
with_isolation() { || ... }
click to toggle source
# File lib/fleiss/backend/active_record/concern.rb, line 109 def with_isolation(&block) conn = self.class.connection if conn.supports_transaction_isolation? && conn.adapter_name != 'SQLite' self.class.transaction(isolation: :repeatable_read, &block) else yield end end