From 67f5ad5ac0383c80647aaebc40cc771829b12b67 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Mon, 5 Aug 2019 11:57:35 +1000 Subject: [PATCH] FEATURE: allow post process mutex to be held longer Previously we would only hold the post process mutex for 1 minute, that is not enough when processing a post with lots of images. This raises the bar to 10 minutes. It also cleans up error reporting around distributed mutexes expiring. We used to double report. --- lib/cooked_post_processor.rb | 2 +- lib/distributed_mutex.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index a0c2efd93b2..ac16eb82c16 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -35,7 +35,7 @@ class CookedPostProcessor end def post_process(bypass_bump: false, new_post: false) - DistributedMutex.synchronize("post_process_#{@post.id}") do + DistributedMutex.synchronize("post_process_#{@post.id}", validity: 10.minutes) do DiscourseEvent.trigger(:before_post_process_cooked, @doc, @post) remove_full_quote_on_direct_reply if new_post post_process_oneboxes diff --git a/lib/distributed_mutex.rb b/lib/distributed_mutex.rb index 420c5bc1436..19f8b5dd4bc 100644 --- a/lib/distributed_mutex.rb +++ b/lib/distributed_mutex.rb @@ -31,11 +31,11 @@ class DistributedMutex yield ensure current_time = redis.time[0] - unless current_time < expire_time - warn("held for too long") + if current_time > expire_time + warn("held for too long, expected max: #{@validity} secs, took an extra #{current_time - expire_time} secs") end - unless unlock(expire_time) + if !unlock(expire_time) && current_time <= expire_time warn("didn't unlock cleanly") end end