consolle 0.2.9 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/Gemfile.lock +1 -1
- data/lib/consolle/adapters/rails_console.rb +45 -31
- data/lib/consolle/cli.rb +2 -1
- data/lib/consolle/constants.rb +6 -0
- data/lib/consolle/server/console_supervisor.rb +9 -3
- data/lib/consolle.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a3baea2a10a98486b313276d58a6bdf7bffcf8418b490c004f756e480f38060
|
|
4
|
+
data.tar.gz: 9385cca18d1b3caa4de57c2efb98c17da15ff7cf9520f35deaf9eb0ebd21aeab
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d7adccc6ed3b0d47cfb80058c6f45eb82454dbe064c57a778f6bf642ddbd6755bca99c93bd460057e25ee0e5347fa006fbf63dfb723e6e2cb6c6b9b23c3fcd68
|
|
7
|
+
data.tar.gz: 99d6ac3e933f46de68891d4d48b05e590e6bd044902f00dc322d468ff136bbe2a839f614da5bf1958e8fb3173df5d5e69f535229aff2ba4cdd1d53beb87d76bf
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.3.0
|
data/Gemfile.lock
CHANGED
|
@@ -5,6 +5,7 @@ require 'json'
|
|
|
5
5
|
require 'timeout'
|
|
6
6
|
require 'securerandom'
|
|
7
7
|
require 'fileutils'
|
|
8
|
+
require_relative '../constants'
|
|
8
9
|
|
|
9
10
|
module Consolle
|
|
10
11
|
module Adapters
|
|
@@ -20,7 +21,7 @@ module Consolle
|
|
|
20
21
|
@rails_env = rails_env || 'development'
|
|
21
22
|
@verbose = verbose
|
|
22
23
|
@command = command || 'bin/rails console'
|
|
23
|
-
@wait_timeout = wait_timeout ||
|
|
24
|
+
@wait_timeout = wait_timeout || Consolle::DEFAULT_WAIT_TIMEOUT
|
|
24
25
|
@server_pid = nil
|
|
25
26
|
end
|
|
26
27
|
|
|
@@ -270,13 +271,20 @@ module Consolle
|
|
|
270
271
|
File.unlink(pid_file) if File.exist?(pid_file)
|
|
271
272
|
end
|
|
272
273
|
|
|
273
|
-
def wait_for_server(timeout:
|
|
274
|
+
def wait_for_server(timeout: Consolle::DEFAULT_WAIT_TIMEOUT)
|
|
274
275
|
deadline = Time.now + timeout
|
|
275
276
|
server_pid = nil
|
|
276
277
|
error_found = false
|
|
277
278
|
error_message = nil
|
|
278
279
|
last_log_check = Time.now
|
|
279
280
|
ssh_auth_detected = false
|
|
281
|
+
|
|
282
|
+
# Record the initial log file position to avoid reading old errors
|
|
283
|
+
initial_log_pos = if File.exist?(@log_path)
|
|
284
|
+
File.size(@log_path)
|
|
285
|
+
else
|
|
286
|
+
0
|
|
287
|
+
end
|
|
280
288
|
|
|
281
289
|
puts "Waiting for console to start (timeout: #{timeout}s)..." if @verbose
|
|
282
290
|
|
|
@@ -290,12 +298,15 @@ module Consolle
|
|
|
290
298
|
rescue Errno::ESRCH
|
|
291
299
|
# Process died - check log for error
|
|
292
300
|
if File.exist?(@log_path)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
301
|
+
File.open(@log_path, 'r') do |f|
|
|
302
|
+
f.seek(initial_log_pos)
|
|
303
|
+
log_content = f.read
|
|
304
|
+
if log_content.include?('[Server] Error:')
|
|
305
|
+
error_lines = log_content.lines.grep(/\[Server\] Error:/)
|
|
306
|
+
error_message = error_lines.last.strip if error_lines.any?
|
|
307
|
+
else
|
|
308
|
+
error_message = "Server process died unexpectedly"
|
|
309
|
+
end
|
|
299
310
|
end
|
|
300
311
|
else
|
|
301
312
|
error_message = "Server process died unexpectedly"
|
|
@@ -308,29 +319,32 @@ module Consolle
|
|
|
308
319
|
# Check log file periodically for errors or SSH auth messages
|
|
309
320
|
if Time.now - last_log_check > 0.5
|
|
310
321
|
last_log_check = Time.now
|
|
311
|
-
if File.exist?(@log_path)
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
322
|
+
if File.exist?(@log_path) && File.size(@log_path) > initial_log_pos
|
|
323
|
+
File.open(@log_path, 'r') do |f|
|
|
324
|
+
f.seek(initial_log_pos)
|
|
325
|
+
log_content = f.read
|
|
326
|
+
|
|
327
|
+
# Check for explicit errors
|
|
328
|
+
if log_content.include?('[Server] Error:')
|
|
329
|
+
error_lines = log_content.lines.grep(/\[Server\] Error:/)
|
|
330
|
+
error_message = error_lines.last.strip if error_lines.any?
|
|
331
|
+
error_found = true
|
|
332
|
+
break
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
# Check for SSH authentication messages
|
|
336
|
+
if !ssh_auth_detected && (log_content.include?('SSH') ||
|
|
337
|
+
log_content.include?('ssh') ||
|
|
338
|
+
log_content.include?('Authenticating') ||
|
|
339
|
+
log_content.include?('authentication') ||
|
|
340
|
+
log_content.include?('1Password') ||
|
|
341
|
+
@command.include?('kamal') ||
|
|
342
|
+
@command.include?('ssh'))
|
|
343
|
+
ssh_auth_detected = true
|
|
344
|
+
puts "SSH authentication detected, extending timeout..." if @verbose
|
|
345
|
+
# Extend deadline for SSH auth
|
|
346
|
+
deadline = Time.now + [timeout, 60].max
|
|
347
|
+
end
|
|
334
348
|
end
|
|
335
349
|
end
|
|
336
350
|
end
|
data/lib/consolle/cli.rb
CHANGED
|
@@ -7,6 +7,7 @@ require 'socket'
|
|
|
7
7
|
require 'timeout'
|
|
8
8
|
require 'securerandom'
|
|
9
9
|
require 'date'
|
|
10
|
+
require_relative 'constants'
|
|
10
11
|
require_relative 'adapters/rails_console'
|
|
11
12
|
|
|
12
13
|
module Consolle
|
|
@@ -132,7 +133,7 @@ module Consolle
|
|
|
132
133
|
LONGDESC
|
|
133
134
|
method_option :rails_env, type: :string, aliases: '-e', desc: 'Rails environment', default: 'development'
|
|
134
135
|
method_option :command, type: :string, aliases: '-c', desc: 'Custom console command', default: 'bin/rails console'
|
|
135
|
-
method_option :wait_timeout, type: :numeric, aliases: '-w', desc: 'Timeout for console startup (seconds)', default:
|
|
136
|
+
method_option :wait_timeout, type: :numeric, aliases: '-w', desc: 'Timeout for console startup (seconds)', default: Consolle::DEFAULT_WAIT_TIMEOUT
|
|
136
137
|
def start
|
|
137
138
|
ensure_rails_project!
|
|
138
139
|
ensure_project_directories
|
|
@@ -4,6 +4,7 @@ require 'pty'
|
|
|
4
4
|
require 'timeout'
|
|
5
5
|
require 'fcntl'
|
|
6
6
|
require 'logger'
|
|
7
|
+
require_relative '../constants'
|
|
7
8
|
require_relative '../errors'
|
|
8
9
|
|
|
9
10
|
# Ruby 3.4.0+ extracts base64 as a default gem
|
|
@@ -32,7 +33,7 @@ module Consolle
|
|
|
32
33
|
@rails_env = rails_env
|
|
33
34
|
@command = command || 'bin/rails console'
|
|
34
35
|
@logger = logger || Logger.new(STDOUT)
|
|
35
|
-
@wait_timeout = wait_timeout ||
|
|
36
|
+
@wait_timeout = wait_timeout || Consolle::DEFAULT_WAIT_TIMEOUT
|
|
36
37
|
@pid = nil
|
|
37
38
|
@reader = nil
|
|
38
39
|
@writer = nil
|
|
@@ -387,12 +388,17 @@ module Consolle
|
|
|
387
388
|
|
|
388
389
|
def wait_for_prompt(timeout: 15, consume_all: false)
|
|
389
390
|
output = +''
|
|
390
|
-
|
|
391
|
+
start_time = Time.now
|
|
392
|
+
deadline = start_time + timeout
|
|
391
393
|
prompt_found = false
|
|
392
394
|
last_data_time = Time.now
|
|
393
395
|
|
|
396
|
+
logger.info "[ConsoleSupervisor] Waiting for prompt with timeout: #{timeout}s (deadline: #{deadline}, now: #{start_time})"
|
|
397
|
+
|
|
394
398
|
loop do
|
|
395
|
-
|
|
399
|
+
current_time = Time.now
|
|
400
|
+
if current_time > deadline
|
|
401
|
+
logger.error "[ConsoleSupervisor] Timeout reached. Current: #{current_time}, Deadline: #{deadline}, Elapsed: #{current_time - start_time}s"
|
|
396
402
|
logger.error "[ConsoleSupervisor] Output so far: #{output.inspect}"
|
|
397
403
|
logger.error "[ConsoleSupervisor] Stripped: #{strip_ansi(output).inspect}"
|
|
398
404
|
raise Timeout::Error, "No prompt after #{timeout} seconds"
|
data/lib/consolle.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: consolle
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- nacyot
|
|
@@ -79,6 +79,7 @@ files:
|
|
|
79
79
|
- lib/consolle.rb
|
|
80
80
|
- lib/consolle/adapters/rails_console.rb
|
|
81
81
|
- lib/consolle/cli.rb
|
|
82
|
+
- lib/consolle/constants.rb
|
|
82
83
|
- lib/consolle/errors.rb
|
|
83
84
|
- lib/consolle/server/console_socket_server.rb
|
|
84
85
|
- lib/consolle/server/console_supervisor.rb
|