discourse/lib/demon
Alan Guo Xiang Tan 7e412cc067
FIX: Demon::EmailSync heartbeat check not consistent
In `Demon::EmailSync#after_fork`, we had the following lines of code:

```
loop do
  break if Discourse.redis.set(HEARTBEAT_KEY, Time.now.to_i, ex: HEARTBEAT_INTERVAL, nx:
true)
  sleep HEARTBEAT_INTERVAL
end
```

What this means is that if the key already exists in Redis, we will
sleep for `Demon::EmailSync::HEARTBEAT_INTERVAL` seconds which has been
set to 60 seconds. This is highly problematic because the expiry of the
Redis key uses the same interval. That means that by the time we break
out of the loop, the Redis key could have expired. The key expiring
is an indication the process is no longer alive leading to the heartbeat
test failing and causing the process to restart for no good reason.

The solution to resolve this problem is to just remove those lines as I
cannot figure out why those lines would even be necessary. There is no
reason why we would need to sleep for a given interval before booting up
the process.

This commit also updates the Redis key, which is used to store the
heartbeat timestamp, to include the process's hostname and pid. We
should not be restarting all `Demon::EmailSync` processes across
different hosts just because one process on a particular host failed.
2025-01-10 14:14:06 +08:00
..
base.rb DEV: Fix undefined method check_email_sync_heartbeat in unicorn conf (#30360) 2024-12-19 10:10:11 +08:00
email_sync.rb FIX: Demon::EmailSync heartbeat check not consistent 2025-01-10 14:14:06 +08:00
rails_autospec.rb DEV: Apply syntax_tree formatting to lib/* 2023-01-09 12:10:19 +00:00
sidekiq.rb DEV: Fix undefined method check_email_sync_heartbeat in unicorn conf (#30360) 2024-12-19 10:10:11 +08:00