From 3ef7613c93985e003e1f07625441706ec120c749 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Thu, 8 Dec 2022 10:45:58 +0100 Subject: [PATCH] Refs #35774 - further refactor EventDaemon::Runner start this eliminates the need for `.initialize` as it moves all the code into `.start` also uses a block for the lockfile, so no file descriptor is leaked --- app/lib/katello/event_daemon/runner.rb | 14 ++++++-------- lib/katello/engine.rb | 1 - 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/lib/katello/event_daemon/runner.rb b/app/lib/katello/event_daemon/runner.rb index e5d87c6da95..1230e93de2e 100644 --- a/app/lib/katello/event_daemon/runner.rb +++ b/app/lib/katello/event_daemon/runner.rb @@ -6,11 +6,6 @@ class Runner @cache = ActiveSupport::Cache::MemoryStore.new class << self - def initialize - FileUtils.mkdir_p(tmp_dir) - FileUtils.touch(lock_file) - end - def settings SETTINGS[:katello][:event_daemon] end @@ -54,10 +49,13 @@ def stop def start return unless runnable? - lockfile = File.open(lock_file, 'r') - begin + + FileUtils.mkdir_p(tmp_dir) + FileUtils.touch(lock_file) + + File.open(lock_file, 'r') do |lockfile| lockfile.flock(File::LOCK_EX) - return if started? # ensure it wasn't started while we waited for the lock + return nil if started? # ensure it wasn't started while we waited for the lock start_monitor_thread write_pid_file diff --git a/lib/katello/engine.rb b/lib/katello/engine.rb index 24c72a4c996..baa6776e233 100644 --- a/lib/katello/engine.rb +++ b/lib/katello/engine.rb @@ -146,7 +146,6 @@ class Engine < ::Rails::Engine ) end - Katello::EventDaemon::Runner.initialize unless Foreman.in_rake? Katello::EventDaemon::Runner.register_service(:candlepin_events, Katello::CandlepinEventListener) Katello::EventDaemon::Runner.register_service(:katello_events, Katello::EventMonitor::PollerThread) Katello::EventDaemon::Runner.register_service(:katello_agent_events, Katello::EventDaemon::Services::AgentEventReceiver) if ::Katello.with_katello_agent?