Skip to content

Commit

Permalink
Refs #35774 - further refactor EventDaemon::Runner start
Browse files Browse the repository at this point in the history
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
  • Loading branch information
evgeni authored and chris1984 committed Jan 5, 2023
1 parent 72a192c commit 3ef7613
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
14 changes: 6 additions & 8 deletions app/lib/katello/event_daemon/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion lib/katello/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 3ef7613

Please sign in to comment.