prevent race conditions when creating archives
This commit is contained in:
parent
dfbe004122
commit
09870c918d
5 changed files with 23 additions and 13 deletions
|
@ -3,6 +3,7 @@
|
|||
# Table name: archives
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# key :text not null
|
||||
# month :date
|
||||
# status :string not null
|
||||
# time_span_type :string not null
|
||||
|
@ -56,4 +57,15 @@ class Archive < ApplicationRecord
|
|||
"procedure-#{procedure.id}-mois-#{I18n.l(month, format: '%Y-%m')}.zip"
|
||||
end
|
||||
end
|
||||
|
||||
def self.find_or_create_archive(time_span_type, month, groupe_instructeurs)
|
||||
create_with(groupe_instructeurs: groupe_instructeurs)
|
||||
.create_or_find_by(time_span_type: time_span_type, month: month, key: generate_cache_key(groupe_instructeurs))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.generate_cache_key(groupe_instructeurs)
|
||||
groupe_instructeurs.map(&:id).sort.join('-')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue