Class: Cybertrain::WebSocket::FeedTableWriter

Inherits:
StatusWriter
  • Object
show all
Defined in:
cybertrain/websocket/feed_table.rb

Overview

The StatusWriter that writes cybertrain_feeds rows, when a database is connected.

Instance Method Summary collapse

Instance Method Details

#status_withdraw(process) ⇒ Integer

Deletes the rows process wrote (its feeds were stopped cleanly). A database error is logged and counts as nothing deleted: the rows then go stale as a crashed process’s would.

Parameters:

  • process (String) —

    “:"

Returns:

  • (Integer) —

    how many rows it deleted



142
143
144
145
146
147
148
149
# File 'cybertrain/websocket/feed_table.rb', line 142

def status_withdraw(process)
  return 0 unless DB.connected?

  FeedTable.delete_process_feeds(process)
rescue Cybertrain::DB::Error, StandardError => e
  Cybertrain.logger.warn("feeds: could not delete this process's status rows: #{e.class.name}: #{e.message}")
  0
end

#status_write(name, process, connected, started_at, last_activity_at, restarts, now) ⇒ Boolean

Writes one feed’s row.

Parameters:

  • name (String) —

    the subscription’s name

  • process (String) —

    “:"

  • connected (Boolean)
  • started_at (Integer) —

    epoch seconds

  • last_activity_at (Integer) —

    epoch seconds, 0 for none yet

  • restarts (Integer)
  • now (Integer) —

    epoch seconds, the row’s updated_at

Returns:

  • (Boolean) —

    true when it wrote the row

Raises:

  • (Cybertrain::DB::Error) —

    when the database is not reachable



131
132
133
134
135
136
# File 'cybertrain/websocket/feed_table.rb', line 131

def status_write(name, process, connected, started_at, last_activity_at, restarts, now)
  return false unless DB.connected?

  FeedTable.upsert_feed(name, process, connected, started_at, last_activity_at, restarts, now)
  true
end