Class: SpoolFileEvent

Inherits:
ApplicationRecord show all
Defined in:
app/models/spool_file_event.rb

Class Method Summary collapse

Methods inherited from ApplicationRecord

descendants_using_encryption, lockbox_options, #timestamp_attributes_for_update_in_model, #valid?

Class Method Details

.build_event(rpo, filename) ⇒ Object

Look for an existing row with same filename and RPO and increase retry attempt if wasn’t successful from previous attempt Otherwise create a new event



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/spool_file_event.rb', line 10

def self.build_event(rpo, filename)
  filename_rpo_date = filename.match(/(.+)_(.+)_/)[1]
  find_by_sql = sanitize_sql_for_conditions(['rpo = :rpo AND filename like :filename',
                                             { rpo:,
                                               filename: "#{filename_rpo_date}%" }])
  event = find_by(find_by_sql)
  if event.present?
    event.update(retry_attempt: event.retry_attempt + 1) if event.successful_at.nil?
    return event
  end

  create(rpo:, filename:)
end