Skip to Content Skip to Search
Methods
C
W

Class Public methods

create_or_find_by(attributes, &block)

# File app/models/db/daily_notification_run.rb, line 14
def create_or_find_by(attributes, &block)
  record = new(attributes, &block)
  transaction(requires_new: true) do
    record.save(validate: false)

    record
  end
rescue ActiveRecord::RecordNotUnique
  find_with = attributes.merge(record.attributes.slice("run_time_epoch"))
  find_by!(find_with)
end

with_table_lock!()

# File app/models/db/daily_notification_run.rb, line 6
def with_table_lock!
  transaction do
    connection.execute("LOCK #{table_name} IN ACCESS EXCLUSIVE MODE NOWAIT")

    yield
  end
end