Module: Fleiss::Backend::ActiveRecord::Concern

Extended by:
ActiveSupport::Concern
Defined in:
lib/fleiss/backend/active_record/concern.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#finish(owner, now: Time.zone.now) ⇒ Boolean

Marks a job as finished.

Parameters:

  • owner (String)

Returns:

  • (Boolean)

    true if successful.



79
80
81
82
83
84
85
86
87
88
# File 'lib/fleiss/backend/active_record/concern.rb', line 79

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_dataHash

Returns serialized job data.

Returns:

  • (Hash)

    serialized job data



54
55
56
# File 'lib/fleiss/backend/active_record/concern.rb', line 54

def job_data
  @job_data ||= JSON.parse(payload)
end

#job_idString

Returns the ActiveJob ID.

Returns:

  • (String)

    the ActiveJob ID



59
60
61
# File 'lib/fleiss/backend/active_record/concern.rb', line 59

def job_id
  job_data['job_id']
end

#reschedule(owner, now: Time.zone.now) ⇒ Object

Reschedules the job to run again.



91
92
93
94
95
96
97
98
99
100
# File 'lib/fleiss/backend/active_record/concern.rb', line 91

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) ⇒ Boolean

Acquires a lock and starts the job.

Parameters:

  • owner (String)

Returns:

  • (Boolean)

    true if job was started.



66
67
68
69
70
71
72
73
74
# File 'lib/fleiss/backend/active_record/concern.rb', line 66

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