Skip to content

Commit

Permalink
Merge pull request #117 from st0012/use-irb-extension-api
Browse files Browse the repository at this point in the history
Use the IRB extension API to add commands to the console
  • Loading branch information
rosa authored May 22, 2024
2 parents 7295d75 + 6a885f9 commit 2d6d7ea
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
7 changes: 4 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PATH
specs:
mission_control-jobs (0.2.1)
importmap-rails
irb (~> 1.13)
rails (>= 7.1)
stimulus-rails
turbo-rails
Expand Down Expand Up @@ -127,8 +128,8 @@ GEM
activesupport (>= 6.0.0)
railties (>= 6.0.0)
io-console (0.7.2)
irb (1.12.0)
rdoc
irb (1.13.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.7.1)
loofah (2.22.0)
Expand Down Expand Up @@ -234,7 +235,7 @@ GEM
redis-namespace (1.11.0)
redis (>= 4)
regexp_parser (2.9.0)
reline (0.5.0)
reline (0.5.5)
io-console (~> 0.5)
resque (2.6.0)
mono_logger (~> 1.0)
Expand Down
15 changes: 15 additions & 0 deletions lib/mission_control/jobs/console/connect_to.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "irb/command"

module MissionControl::Jobs::Console
class ConnectTo < IRB::Command::Base
category "Mission control jobs"
description "Connect to a job server"

def execute(server_locator)
server = MissionControl::Jobs::Server.from_global_id(server_locator)
MissionControl::Jobs::Current.server = server

puts "Connected to #{server_locator}"
end
end
end
26 changes: 0 additions & 26 deletions lib/mission_control/jobs/console/helpers.rb

This file was deleted.

23 changes: 23 additions & 0 deletions lib/mission_control/jobs/console/jobs_help.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "irb/command"

module MissionControl::Jobs::Console
class JobsHelp < IRB::Command::Base
category "Mission control jobs"
description "Show help for managing jobs"

def execute(*)
puts "You are currently connected to #{MissionControl::Jobs::Current.server}" if MissionControl::Jobs::Current.server

puts "You can connect to a job server with"
puts %( connect_to <app_id>:<server_id>\n\n)

puts "Available job servers:\n"

MissionControl::Jobs.applications.each do |application|
application.servers.each do |server|
puts " * #{server.to_global_id}"
end
end
end
end
end
5 changes: 3 additions & 2 deletions lib/mission_control/jobs/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ class Engine < ::Rails::Engine

console do
require "irb"
require "irb/context"

IRB::Command.register :connect_to, Console::ConnectTo
IRB::Command.register :jobs_help, Console::JobsHelp

IRB::Context.prepend(MissionControl::Jobs::Console::Context)
Rails::ConsoleMethods.include(MissionControl::Jobs::Console::Helpers)

MissionControl::Jobs.delay_between_bulk_operation_batches = 2
MissionControl::Jobs.logger = ActiveSupport::Logger.new(STDOUT)
Expand Down
1 change: 1 addition & 0 deletions mission_control-jobs.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "importmap-rails"
spec.add_dependency "turbo-rails"
spec.add_dependency "stimulus-rails"
spec.add_dependency "irb", "~> 1.13"

spec.add_development_dependency "resque"
spec.add_development_dependency "solid_queue"
Expand Down

0 comments on commit 2d6d7ea

Please sign in to comment.