Skip to content

Instantly share code, notes, and snippets.

@kpheasey
Created March 3, 2017 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpheasey/3df5ed64a99933be211f76fae12ffcc3 to your computer and use it in GitHub Desktop.
Save kpheasey/3df5ed64a99933be211f76fae12ffcc3 to your computer and use it in GitHub Desktop.
worker method that freezes
def calculate!
self.with_lock do
Octopus.using(:replica) do
self.class::CALCULATION_METHODS.each { |method| send(method) }
end
self.updated_at = self.calculated_at = Time.now
self.is_calculated = true
self.save!(touch: false)
end
rescue ActiveRecord::StatementInvalid => e
if e.message.downcase.include?('deadlock')
raise CalculationDeadLock, e.message
else
raise
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment