about summary refs log tree commit diff
path: root/app/models/account_migration.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-05-16 10:43:44 +0200
committerGitHub <noreply@github.com>2022-05-16 10:43:44 +0200
commit3a084113067656ef9318b9fb5bcfea4fd2de6ffe (patch)
tree251a14cd362a6d98c1721e8f3f54fc386165e464 /app/models/account_migration.rb
parent94e98864e39c010635e839fea984f2b4893bef1a (diff)
parent040b7d37a460e5f023f7654b1b619368cbbc24ea (diff)
Merge pull request #1772 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/models/account_migration.rb')
-rw-r--r--app/models/account_migration.rb13
1 files changed, 3 insertions, 10 deletions
diff --git a/app/models/account_migration.rb b/app/models/account_migration.rb
index ded32c9c6..06291c9f3 100644
--- a/app/models/account_migration.rb
+++ b/app/models/account_migration.rb
@@ -15,6 +15,7 @@
 
 class AccountMigration < ApplicationRecord
   include Redisable
+  include Lockable
 
   COOLDOWN_PERIOD = 30.days.freeze
 
@@ -41,12 +42,8 @@ class AccountMigration < ApplicationRecord
 
     return false unless errors.empty?
 
-    RedisLock.acquire(lock_options) do |lock|
-      if lock.acquired?
-        save
-      else
-        raise Mastodon::RaceConditionError
-      end
+    with_lock("account_migration:#{account.id}") do
+      save
     end
   end
 
@@ -83,8 +80,4 @@ class AccountMigration < ApplicationRecord
   def validate_migration_cooldown
     errors.add(:base, I18n.t('migrations.errors.on_cooldown')) if account.migrations.within_cooldown.exists?
   end
-
-  def lock_options
-    { redis: redis, key: "account_migration:#{account.id}" }
-  end
 end