Class: Rubino::CLI::JobsCommand

Inherits:
Thor
  • Object
show all
Defined in:
lib/rubino/cli/jobs_command.rb

Overview

Subcommands for managing the job queue

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rubino/cli/jobs_command.rb', line 12

def self.exit_on_failure?
  true
end

.render_list(jobs, ui:) ⇒ Object

ONE jobs-table rendering for both surfaces (#187): this CLI verb and the in-chat /jobs list (Commands::Executor).



34
35
36
37
38
39
40
# File 'lib/rubino/cli/jobs_command.rb', line 34

def self.render_list(jobs, ui:)
  rows = jobs.map do |j|
    [j[:id][0..7], j[:type], j[:status], j[:attempts].to_s, j[:run_at]]
  end

  ui.table(headers: %w[ID Type Status Attempts RunAt], rows: rows)
end

Instance Method Details

#listObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubino/cli/jobs_command.rb', line 19

def list
  Rubino.ensure_database_ready!
  queue = Jobs::Queue.new
  jobs = queue.list(status: options[:status], limit: options[:limit])

  if jobs.empty?
    Rubino.ui.info("No jobs found.")
    return
  end

  self.class.render_list(jobs, ui: Rubino.ui)
end

#processObject



44
45
46
47
48
# File 'lib/rubino/cli/jobs_command.rb', line 44

def process
  runner = Jobs::Runner.new
  processed = runner.run_pending(limit: options[:limit])
  Rubino.ui.success("Processed #{processed} job(s)")
end

#workerObject



51
52
53
54
55
56
57
# File 'lib/rubino/cli/jobs_command.rb', line 51

def worker
  Rubino.ui.info("Starting job worker (poll every #{Rubino.configuration.jobs_poll_interval}s)...")
  Rubino.ui.info("Press Ctrl+C to stop.")

  worker = Jobs::Worker.new
  worker.start
end