run_loop 1.2.0.pre1 → 1.2.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/run_loop/core.rb +36 -13
- data/lib/run_loop/version.rb +1 -1
- data/scripts/run_loop_host.js +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfc436b93536dc5fc25891e526a80a1b524dd94e
|
4
|
+
data.tar.gz: 119009225a74e03e009710319db28773d3d89e0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 219265bba39959c8949ca278aa8e68d07d206f19cbbf6ffd660404de790ab3610e2bee7dde5f7454df9befa88b9ef40515b5132688ddf8978a2f7d360e5c8044
|
7
|
+
data.tar.gz: 1f02e149ce98e667c35194ae31cb8da6cc3f3f9621efacacf5a49385144395592b27e5387fd12c522a9325472c5579f231d7a9304f884f2607c1c9c08e1446c1
|
data/lib/run_loop/core.rb
CHANGED
@@ -11,6 +11,9 @@ module RunLoop
|
|
11
11
|
class TimeoutError < RuntimeError
|
12
12
|
end
|
13
13
|
|
14
|
+
class WriteFailedError < RuntimeError
|
15
|
+
end
|
16
|
+
|
14
17
|
module Core
|
15
18
|
|
16
19
|
START_DELIMITER = "OUTPUT_JSON:\n"
|
@@ -488,23 +491,47 @@ module RunLoop
|
|
488
491
|
RUBY_PLATFORM == 'java'
|
489
492
|
end
|
490
493
|
|
491
|
-
def self.write_request(run_loop, cmd)
|
494
|
+
def self.write_request(run_loop, cmd, logger=nil)
|
492
495
|
repl_path = run_loop[:repl_path]
|
493
496
|
index = run_loop[:index]
|
494
497
|
cmd_str = "#{index}:#{escape_host_command(cmd)}"
|
495
|
-
|
496
|
-
|
498
|
+
should_log = (ENV['DEBUG'] == '1')
|
499
|
+
RunLoop.log_info(logger, cmd_str) if should_log
|
500
|
+
write_succeeded = false
|
501
|
+
2.times do |i|
|
502
|
+
RunLoop.log_info(logger, "Trying write of command #{cmd_str} at index #{index}") if should_log
|
503
|
+
File.open(repl_path, 'w') { |f| f.puts(cmd_str) }
|
504
|
+
write_succeeded = validate_index_written(run_loop, index, logger)
|
505
|
+
break if write_succeeded
|
506
|
+
end
|
507
|
+
unless write_succeeded
|
508
|
+
RunLoop.log_info(logger, 'Failing...Raising RunLoop::WriteFailedError') if should_log
|
509
|
+
raise RunLoop::WriteFailedError.new("Trying write of command #{cmd_str} at index #{index}")
|
510
|
+
end
|
497
511
|
run_loop[:index] = index + 1
|
498
512
|
|
499
513
|
index
|
500
514
|
end
|
501
515
|
|
516
|
+
def self.validate_index_written(run_loop, index, logger)
|
517
|
+
begin
|
518
|
+
Timeout::timeout(10, TimeoutError) do
|
519
|
+
Core.read_response(run_loop, index, 10, 'last_index')
|
520
|
+
end
|
521
|
+
RunLoop.log_info(logger, "validate index written for index #{index} ok")
|
522
|
+
return true
|
523
|
+
rescue TimeoutError => _
|
524
|
+
RunLoop.log_info(logger, "validate index written for index #{index} failed. Retrying.")
|
525
|
+
return false
|
526
|
+
end
|
527
|
+
end
|
528
|
+
|
502
529
|
def self.escape_host_command(cmd)
|
503
530
|
backquote = "\\"
|
504
531
|
cmd.gsub(backquote,backquote*4)
|
505
532
|
end
|
506
533
|
|
507
|
-
def self.read_response(run_loop, expected_index, empty_file_timeout=10)
|
534
|
+
def self.read_response(run_loop, expected_index, empty_file_timeout=10, search_for_property='index')
|
508
535
|
|
509
536
|
log_file = run_loop[:log_file]
|
510
537
|
initial_offset = run_loop[:initial_offset] || 0
|
@@ -566,7 +593,7 @@ module RunLoop
|
|
566
593
|
if ENV['DEBUG_READ']=='1'
|
567
594
|
p parsed_result
|
568
595
|
end
|
569
|
-
json_index_if_present = parsed_result[
|
596
|
+
json_index_if_present = parsed_result[search_for_property]
|
570
597
|
if json_index_if_present && json_index_if_present == expected_index
|
571
598
|
result = parsed_result
|
572
599
|
break
|
@@ -792,16 +819,12 @@ module RunLoop
|
|
792
819
|
expected_index = run_loop[:index]
|
793
820
|
result = nil
|
794
821
|
begin
|
795
|
-
expected_index = Core.write_request(run_loop, cmd)
|
796
|
-
rescue Errno::EINTR =>
|
822
|
+
expected_index = Core.write_request(run_loop, cmd, logger)
|
823
|
+
rescue RunLoop::WriteFailedError, Errno::EINTR => write_error
|
797
824
|
# Attempt recover from interrupt by attempting to read result (assuming write went OK)
|
798
825
|
# or retry if attempted read result fails
|
799
826
|
run_loop[:index] = expected_index # restore expected index in case it changed
|
800
|
-
log_info(logger, "Core.write_request
|
801
|
-
sleep(1) # Arbitrary wait in hope that the system condition causing the interrupt passes
|
802
|
-
if intr_error && intr_error.backtrace
|
803
|
-
log_info(logger, "backtrace: #{intr_error.backtrace.join("\n")}")
|
804
|
-
end
|
827
|
+
log_info(logger, "Core.write_request failed: #{write_error}. Attempting recovery...")
|
805
828
|
log_info(logger, "Attempting read in case the request was received... Please wait (#{interrupt_retry_timeout})...")
|
806
829
|
begin
|
807
830
|
Timeout::timeout(interrupt_retry_timeout, TimeoutError) do
|
@@ -813,7 +836,7 @@ module RunLoop
|
|
813
836
|
return result
|
814
837
|
rescue TimeoutError => _
|
815
838
|
log_info(logger, "Read did not result in a response for index #{expected_index}... Retrying send_command...")
|
816
|
-
return send_command(run_loop, cmd, options, num_retries+1,
|
839
|
+
return send_command(run_loop, cmd, options, num_retries+1, write_error)
|
817
840
|
end
|
818
841
|
end
|
819
842
|
|
data/lib/run_loop/version.rb
CHANGED
data/scripts/run_loop_host.js
CHANGED
@@ -302,7 +302,7 @@ while (true) {
|
|
302
302
|
_actualIndex = parseInt(_input.substring(0, _index), 10);
|
303
303
|
if (!isNaN(_actualIndex) && _actualIndex >= _expectedIndex) {
|
304
304
|
_exp = _input.substring(_index + 1, _input.length);
|
305
|
-
|
305
|
+
Log.output(_actualIndex);
|
306
306
|
_result = eval(_exp);
|
307
307
|
}
|
308
308
|
else {//likely old command is lingering...
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: run_loop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.
|
4
|
+
version: 1.2.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karl Krukow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|