Class: EzLogsAgent::FlushScheduler

Inherits:
Object
  • Object
show all
Defined in:
lib/ez_logs_agent/flush_scheduler.rb

Overview

FlushScheduler orchestrates periodic flushing of buffered events to the server.

Responsibilities:

  • Start a single background thread that wakes up every ‘send_interval` seconds

  • Flush Buffer and send events via RetrySender

  • Shut down cleanly when requested

Non-responsibilities:

  • Does NOT retry (RetrySender handles that)

  • Does NOT interpret Transport results

  • Does NOT manage Rails lifecycle (Railtie handles that)

  • Does NOT mutate or inspect events

Class Method Summary collapse

Class Method Details

.running?Boolean

Check if the scheduler is currently running

Returns:

  • (Boolean)


46
47
48
# File 'lib/ez_logs_agent/flush_scheduler.rb', line 46

def running?
  @thread&.alive? == true
end

.startObject

Start the background flush thread Idempotent: safe to call multiple times



20
21
22
23
24
25
26
27
28
29
# File 'lib/ez_logs_agent/flush_scheduler.rb', line 20

def start
  return if running?

  @stop_requested = false
  @thread = Thread.new { run_loop }

  Logger.debug("[FlushScheduler] Started")
rescue => error
  Logger.error("[FlushScheduler] Failed to start: #{error.class} - #{error.message}")
end

.stopObject

Stop the background flush thread Blocks until thread exits Idempotent: safe to call multiple times



34
35
36
37
38
39
40
41
42
43
# File 'lib/ez_logs_agent/flush_scheduler.rb', line 34

def stop
  return unless running?

  @stop_requested = true
  @thread.join if @thread

  Logger.debug("[FlushScheduler] Stopped")
rescue => error
  Logger.error("[FlushScheduler] Failed to stop: #{error.class} - #{error.message}")
end