Class: SourceMonitor::ImportSessions::HealthCheckBroadcaster

Inherits:
Object
  • Object
show all
Includes:
ActionView::RecordIdentifier
Defined in:
lib/source_monitor/import_sessions/health_check_broadcaster.rb

Instance Method Summary collapse

Constructor Details

#initialize(import_session) ⇒ HealthCheckBroadcaster

Returns a new instance of HealthCheckBroadcaster.



10
11
12
# File 'lib/source_monitor/import_sessions/health_check_broadcaster.rb', line 10

def initialize(import_session)
  @import_session = import_session
end

Instance Method Details

#broadcast_progressObject



29
30
31
32
33
34
35
36
37
# File 'lib/source_monitor/import_sessions/health_check_broadcaster.rb', line 29

def broadcast_progress
  return unless turbo_available?

  Turbo::StreamsChannel.broadcast_replace_to(
    stream_name,
    target: progress_target,
    html: render_progress
  )
end

#broadcast_row(entry) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/source_monitor/import_sessions/health_check_broadcaster.rb', line 18

def broadcast_row(entry)
  return unless turbo_available?
  return unless entry

  Turbo::StreamsChannel.broadcast_replace_to(
    stream_name,
    target: row_target(entry),
    html: render_row(entry)
  )
end

#progress_dataObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/source_monitor/import_sessions/health_check_broadcaster.rb', line 39

def progress_data
  entries = health_entries
  total = import_session.health_check_targets.size
  completed = entries.count { |entry| %w[working failing].include?(entry[:health_status].to_s) }

  {
    completed: completed,
    total: total,
    pending: [ total - completed, 0 ].max,
    active: import_session.health_checks_active?,
    done: total.positive? && completed >= total
  }
end

#stream_nameObject



14
15
16
# File 'lib/source_monitor/import_sessions/health_check_broadcaster.rb', line 14

def stream_name
  import_session.health_stream_name
end