Module: Cybertrain::Main
- Defined in:
- cybertrain/main.rb,
cybertrain/jobs.rb
Overview
Cybertrain::Main – what bin/
./blog serve (port from PORT / config) ./blog server 3000 serve on 3000 (a bare “3000” too: the dev loop’s execv passes the port that way) ./blog migrate apply db/migrate (gen/migrations.rb) ./blog db status any DB::CLI command: status, rollback N, schema, schema:dump, create, backup PATH, vacuum ./blog worker jobs and scheduled tasks, no HTTP (several may share a database) ./blog jobs list any Job::CLI command: list [STATE], retry ID|–all, discard ID, delete ID, prune [–before DAYS] (worker and jobs with require “cybertrain/jobs”: JobsFeature#run_feature_command) ./blog feeds [NAME…] the WebSocket subscriptions (all, or the named ones) ./blog feeds status each feed’s health, from the status rows ./blog console the expression console over the models (Console.run) ./blog dbconsole the sqlite3 shell on the configured database ./blog user a@b.c a command the application registered with Main.command
gen stays a separate bin/gen.rb: it needs the generator and the
routes/schema DSL, none of which belong in the production binary.
Class Method Summary collapse
-
.command(name, description) {|argv| ... } ⇒ nil
Registers an operational command for the application’s binary:
./<name> NAME ARGS...runs the block instead of the server, and./<name> helplists it. -
.feeds?(argv) ⇒ Boolean
Whether Main.run runs these arguments as
./<app> feeds [NAME...]: the WebSocket subscriptions, no HTTP and no jobs. -
.server?(argv) ⇒ Boolean
Whether Main.run starts the server for these arguments: [], [“server”], [“
"], ["server", " "]; never a registered command's name, so whatever starts only for a server (the scheduler, a boot-time check) stays off for a one-shot command. -
.worker?(argv) ⇒ Boolean
Whether Main.run runs these arguments as
./<app> worker: the jobs and the scheduler, no HTTP.
Class Method Details
.command(name, description) {|argv| ... } ⇒ nil
Registers an operational command for the application’s binary:
./<name> NAME ARGS... runs the block instead of the server, and
./<name> help lists it. Call it in bin/
Before the block runs, Cybertrain::DB is connected to
Cybertrain.config.database_path with a pool of one connection (and
disconnected afterwards), the way ./<name> db ... works, and the
views and the URL resolver are configured as the server’s boot does,
so Cybertrain::Views.render_partial, render_component and the
Stream.broadcast_*_to(partial: / component:) shortcuts work; no
server, scheduler, threads or session secret are set up. A Cybertrain::DB::Error raised
by the block (or by the connect) prints NAME failed: MESSAGE and
exits 1. Any other exception is not rescued.
The block receives the arguments after the command’s name as its one
argument (Spinel has no instance_eval, so there is no implicit
receiver, like before_action { |c| ... }) and returns the exit
status, an Integer.
93 94 95 96 97 98 99 |
# File 'cybertrain/main.rb', line 93 def self.command(name, description, &block) problem = command_name_problem(name) raise ArgumentError, "Main.command #{name.inspect}: #{problem}" unless problem.empty? COMMANDS << Command.new(name, description, block) nil end |
.feeds?(argv) ⇒ Boolean
Whether run runs these arguments as ./<app> feeds [NAME...]:
the WebSocket subscriptions, no HTTP and no jobs.
333 334 335 |
# File 'cybertrain/main.rb', line 333 def self.feeds?(argv) !argv.empty? && argv[0] == "feeds" end |
.server?(argv) ⇒ Boolean
Whether run starts the server for these arguments: [],
[“server”], [“
311 312 313 314 315 316 317 |
# File 'cybertrain/main.rb', line 311 def self.server?(argv) return true if argv.empty? return false if command_index(argv[0]) >= 0 return true if argv[0] == "server" Application.port_argument(argv) > 0 end |
.worker?(argv) ⇒ Boolean
Whether run runs these arguments as ./<app> worker: the
jobs and the scheduler, no HTTP.
324 325 326 |
# File 'cybertrain/main.rb', line 324 def self.worker?(argv) !argv.empty? && argv[0] == "worker" end |