Class: SolidObjects::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/solid_objects/cli.rb,
sig/generated/lib/solid_objects/cli.rbs

Instance Method Summary collapse

Instance Method Details

#authorize_administration!(action) ⇒ void

This method returns an undefined value.

RBS:

  • (Symbol) -> void

Parameters:

  • (Symbol)


106
107
108
109
110
111
112
113
114
115
116
# File 'lib/solid_objects/cli.rb', line 106

def authorize_administration!(action)
  authorized = SolidObjects.configuration.authorize_administration.call(
    action:,
    resource: "processes",
    resource_id: nil,
    authorization_context: { source: "cli" }
  )
  return if authorized

  raise Unauthorized, "actor administration is not authorized"
end

#boot_applicationvoid

This method returns an undefined value.

RBS:

  • () -> void



89
90
91
92
93
94
95
96
97
# File 'lib/solid_objects/cli.rb', line 89

def boot_application
  path = options[:environment] ||
    File.expand_path("config/environment.rb", Dir.pwd)
  unless File.file?(path)
    raise Error, "Rails environment not found at #{path}"
  end

  require path
end

#cleanupvoid

This method returns an undefined value.

RBS:

  • () -> void



55
56
57
58
59
# File 'lib/solid_objects/cli.rb', line 55

def cleanup
  boot_application
  authorize_administration!(:cleanup)
  puts JSON.generate(cleaned_processes: ProcessRegistry.cleanup_dead)
end

#dead_lettersvoid

This method returns an undefined value.

RBS:

  • () -> void



65
66
67
68
69
70
71
# File 'lib/solid_objects/cli.rb', line 65

def dead_letters
  boot_application
  rows = SolidObjects.dead_letters
    .all(authorization_context: { source: "cli" })
    .map(&:attributes)
  puts JSON.pretty_generate(rows)
end

#numeric_option(name, default) ⇒ Integer

RBS:

  • (Symbol, Integer) -> Integer

Parameters:

  • (Symbol)
  • (Integer)

Returns:

  • (Integer)


100
101
102
103
# File 'lib/solid_objects/cli.rb', line 100

def numeric_option(name, default)
  value = options[name]
  value ? Integer(value) : default
end

#retry_dead_letter(id) ⇒ void

This method returns an undefined value.

RBS:

  • (String) -> void

Parameters:

  • (String)


77
78
79
80
81
82
83
84
# File 'lib/solid_objects/cli.rb', line 77

def retry_dead_letter(id)
  boot_application
  message_reference = SolidObjects.dead_letters.retry(
    Integer(id),
    authorization_context: { source: "cli" }
  )
  puts JSON.generate(message_id: message_reference.id)
end

#startvoid

This method returns an undefined value.

RBS:

  • () -> void



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/solid_objects/cli.rb', line 17

def start
  boot_application
  supervisor = Supervisor.new(
    worker_count: numeric_option(:workers, SolidObjects.configuration.worker_count),
    effect_worker_count: numeric_option(:effect_workers, SolidObjects.configuration.effect_worker_count),
    broadcast_worker_count: numeric_option(:broadcast_workers, SolidObjects.configuration.broadcast_worker_count),
    reminder_scheduler_count: numeric_option(:reminder_schedulers, SolidObjects.configuration.reminder_scheduler_count)
  )
  %w[INT TERM].each do |signal|
    Signal.trap(signal) { Thread.new { supervisor.stop } }
  end
  supervisor.run
end

#statusvoid

This method returns an undefined value.

RBS:

  • () -> void



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/solid_objects/cli.rb', line 35

def status
  boot_application
  authorize_administration!(:status)
  rows = SolidObjects::Process.order(:kind, :started_at).map do |process_record|
    {
      id: process_record.id,
      kind: process_record.kind,
      hostname: process_record.hostname,
      pid: process_record.pid,
      state: process_record.shutdown_state,
      last_heartbeat_at: process_record.last_heartbeat_at
    }
  end
  puts JSON.pretty_generate(rows)
end