Class: Lescopr::Core::DaemonRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/lescopr/core/daemon_runner.rb

Overview

Background thread that flushes the log queue every N seconds and sends heartbeats every 30 s.

Constant Summary collapse

FLUSH_INTERVAL =

seconds

5
HEARTBEAT_INTERVAL =

seconds

30

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ DaemonRunner

Returns a new instance of DaemonRunner.



11
12
13
14
15
16
# File 'lib/lescopr/core/daemon_runner.rb', line 11

def initialize(client)
  @client   = client
  @running  = false
  @thread   = nil
  @mutex    = Mutex.new
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/lescopr/core/daemon_runner.rb', line 36

def running?
  @running
end

#startObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/lescopr/core/daemon_runner.rb', line 18

def start
  @mutex.synchronize do
    return if @running

    @running = true
    @thread  = Thread.new { run_loop }
    @thread.name = "lescopr-daemon"
    @thread.abort_on_exception = false
  end
end

#stopObject



29
30
31
32
33
34
# File 'lib/lescopr/core/daemon_runner.rb', line 29

def stop
  @mutex.synchronize do
    @running = false
  end
  @thread&.join(3)
end