diff options
| author | Teddy Wing | 2017-12-12 16:56:49 +0100 | 
|---|---|---|
| committer | Teddy Wing | 2017-12-12 16:56:49 +0100 | 
| commit | 55b995531b2504792dfa1b0314b5cc5b55a775ac (patch) | |
| tree | fe3f43a490e28fa3064541292eea6180692b31c3 /app/models/referential.rb | |
| parent | c84154201959197a99de202d97baff1c812dead9 (diff) | |
| download | chouette-core-55b995531b2504792dfa1b0314b5cc5b55a775ac.tar.bz2 | |
Referential: Raise an error if the table lock times out
Paired with Johan on this one. There's an internal timeout on our table
lock. If it's reached, an
`ActiveRecord::StatementInvalid<PG::LockNotAvailable>` error is raised.
Use a custom error instead by "overriding" `#save` with a method that
raises our custom error in that case instead. This will enable us to
provide a custom user-facing error in the event this happens.
Refs #5024
Diffstat (limited to 'app/models/referential.rb')
| -rw-r--r-- | app/models/referential.rb | 12 | 
1 files changed, 12 insertions, 0 deletions
| diff --git a/app/models/referential.rb b/app/models/referential.rb index b14ab3827..b44bb15c6 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -61,6 +61,18 @@ class Referential < ActiveRecord::Base    scope :order_by_validity_period, ->(dir) { joins(:metadatas).order("unnest(periodes) #{dir}") }    scope :order_by_lines, ->(dir) { joins(:metadatas).group("referentials.id").order("sum(array_length(referential_metadata.line_ids,1)) #{dir}") } +  def save_with_table_lock_timeout +    save_without_table_lock_timeout +  rescue ActiveRecord::StatementInvalid => e +    if e.message.include?('PG::LockNotAvailable') +      raise TableLockTimeoutError.new(e) +    else +      raise +    end +  end + +  alias_method_chain :save, :table_lock_timeout +    def lines      if metadatas.blank?        workbench ? workbench.lines : associated_lines | 
