Class: Cybertrain::Background::Service

Inherits:
Object
  • Object
show all
Defined in:
cybertrain/background.rb

Overview

A background service: the default does nothing. Subclasses override all three methods. Distinctive names (service_start, not start): NOTES rules 10/34/62.

Instance Method Summary collapse

Instance Method Details

#service_dead_feeds ⇒ Array<String>

The names of the parts #service_start started whose thread has ended (a feed whose loop raised past its rescues), for the supervisor (Cybertrain::Background.supervise!) to start again. The default has none.

Returns:

  • (Array<String>)


97
98
99
# File 'cybertrain/background.rb', line 97

def service_dead_feeds
  Background::NO_NAMES
end

#service_feed_names ⇒ Array<String>

The names #service_start_only accepts (a feed service’s feeds), for ./<app> feeds NAME... to check its arguments against. The default has none.

Returns:

  • (Array<String>)


70
71
72
# File 'cybertrain/background.rb', line 70

def service_feed_names
  Background::NO_NAMES
end

#service_feed_restarts(name) ⇒ Integer

How many times #service_restart_feed started the part name again: the supervisor waits min(30, 2 ** that) seconds before the next restart.

Parameters:

  • name (String)

Returns:



107
108
109
# File 'cybertrain/background.rb', line 107

def service_feed_restarts(name)
  0
end

#service_name ⇒ String

Returns for the log and for Cybertrain::Background.register’s uniqueness check; non-empty in a subclass.

Returns:



36
37
38
# File 'cybertrain/background.rb', line 36

def service_name
  ""
end

#service_problem ⇒ String

What would make service_start refuse to start, found before the server binds its port (Cybertrain::Background.boot_problem), so serve reports it as a boot failure rather than raising after the banner.

Returns:

  • (String) —

    ”” when nothing is wrong



87
88
89
# File 'cybertrain/background.rb', line 87

def service_problem
  ""
end

#service_publish_status(now) ⇒ Integer

Writes the parts’ status where other processes can read it (the feeds’ cybertrain_feeds rows), called by the supervisor every Config#feed_status_interval seconds.

Parameters:

Returns:

  • (Integer) —

    how many rows it wrote



125
126
127
# File 'cybertrain/background.rb', line 125

def service_publish_status(now)
  0
end

#service_restart_feed(name) ⇒ Boolean

Starts the dead part name again (a new thread).

Parameters:

  • name (String)

Returns:

  • (Boolean) —

    true when it started one



115
116
117
# File 'cybertrain/background.rb', line 115

def service_restart_feed(name)
  false
end

#service_start(config) ⇒ Boolean

Starts the service (its thread, usually). Called once per serve; it must not block and should not raise.

Parameters:

Returns:

  • (Boolean) —

    true when it started something



45
46
47
# File 'cybertrain/background.rb', line 45

def service_start(config)
  false
end

#service_start_only(config, names) ⇒ Boolean

Starts only the parts of the service named in names (./<app> feeds NAME...); all of it when names is empty. The default, for a service without named parts, calls #service_start when names is empty and starts nothing otherwise: ./<app> feeds trades runs that one feed and nothing else, while a bare ./<app> feeds runs every service (judgement call).

Parameters:

  • config (Config)
  • names (Array<String>)

Returns:

  • (Boolean) —

    true when it started something



59
60
61
62
63
# File 'cybertrain/background.rb', line 59

def service_start_only(config, names)
  return false unless names.empty?

  service_start(config)
end

#service_stop ⇒ nil

Asks the service to end. Called once at shutdown, also for a service whose service_start returned false: then it does nothing.

Returns:

  • (nil)


78
79
80
# File 'cybertrain/background.rb', line 78

def service_stop
  nil
end

#service_withdraw_status ⇒ Integer

Deletes the status rows #service_publish_status wrote for this process, after a clean stop of the feeds role. It should not raise.

Returns:

  • (Integer) —

    how many rows it deleted



134
135
136
# File 'cybertrain/background.rb', line 134

def service_withdraw_status
  0
end