From a25a5c07f36b00ba5a199c6cf670c723c25bc82e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Gaya?= <sebastien.gaya@gmail.com>
Date: Fri, 31 May 2024 11:01:53 +0200
Subject: [PATCH] fix

---
 app/models/communication/website/with_lock.rb | 5 ++---
 db/schema.rb                                  | 3 ++-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/app/models/communication/website/with_lock.rb b/app/models/communication/website/with_lock.rb
index ec40fa218..97b68f32f 100644
--- a/app/models/communication/website/with_lock.rb
+++ b/app/models/communication/website/with_lock.rb
@@ -8,9 +8,8 @@ module Communication::Website::WithLock
 
   def locked_for_background_jobs?(executing_job_id)
     reload
-    locked_at.present? && # Not locked if locked_at is nil
-    locked_by_job_id != executing_job_id && # If the website was locked by the same job, we can continue
-    GoodJob::Job.running.find_by(id: locked_by_job_id).present? # Check if the locking job is still running (to handle SIGKILL and hard shutdowns)
+    # Website is locked if locked_at is present and the job which locked it is not the current job
+    locked_at.present? && locked_by_job_id != executing_job_id
   end
 
   def lock_for_background_jobs!(job_id)
diff --git a/db/schema.rb b/db/schema.rb
index b62ae4ede..b30bc636f 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema[7.1].define(version: 2024_05_18_073335) do
+ActiveRecord::Schema[7.1].define(version: 2024_05_31_082129) do
   # These are extensions that must be enabled in order to support this database
   enable_extension "pg_trgm"
   enable_extension "pgcrypto"
@@ -663,6 +663,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_05_18_073335) do
     t.datetime "locked_at"
     t.datetime "git_files_analysed_at"
     t.boolean "highlighted_in_showcase", default: false
+    t.uuid "locked_by_job_id"
     t.index ["about_type", "about_id"], name: "index_communication_websites_on_about"
     t.index ["default_language_id"], name: "index_communication_websites_on_default_language_id"
     t.index ["name"], name: "index_communication_websites_on_name", opclass: :gin_trgm_ops, using: :gin
-- 
GitLab