Created
March 3, 2017 20:14
-
-
Save kpheasey/3df5ed64a99933be211f76fae12ffcc3 to your computer and use it in GitHub Desktop.
worker method that freezes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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