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.



84
85
86
87
88
89
90
91
92
93
# 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_dataHash

Returns serialized job data.

Returns:

  • (Hash)

    serialized job data



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

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

#job_idString

Returns the ActiveJob ID.

Returns:

  • (String)

    the ActiveJob ID



64
65
66
# File 'lib/fleiss/backend/active_record/concern.rb', line 64

def job_id
  job_data['job_id']
end

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

Reschedules the job to run again.



96
97
98
99
100
101
102
103
104
105
# 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) ⇒ Boolean

Acquires a lock and starts the job.

Parameters:

  • owner (String)

Returns:

  • (Boolean)

    true if job was started.



71
72
73
74
75
76
77
78
79
# 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