lib/gorgon/originator.rb in gorgon-0.10.5 vs lib/gorgon/originator.rb in gorgon-0.11.0
- old
+ new
@@ -16,30 +16,37 @@
require 'socket'
class Originator
include Configuration
+ SPEC_SUCCESS_EXIT_STATUS = 0
+ SPEC_FAILURE_EXIT_STATUS = 1
+ SYNC_ERROR_EXIT_STATUS = 2
+ ERROR_EXIT_STATUS = 3
+
+
def initialize
@configuration = nil
end
def originate
begin
Signal.trap("INT") { ctrl_c }
Signal.trap("TERM") { ctrl_c }
- publish
+ exit_status = publish
@logger.log "Originator finished successfully"
+ exit_status
rescue StandardError
$stderr.puts "Unhandled exception in originator:"
$stderr.puts $!.message
$stderr.puts $!.backtrace.join("\n")
$stderr.puts "----------------------------------"
$stderr.puts "Now attempting to cancel the job."
@logger.log_error "Unhandled Exception!" if @logger
cancel_job
- exit 2
+ exit ERROR_EXIT_STATUS
end
end
def cancel_job
ShutdownManager.new(protocol: @protocol, job_state: @job_state).cancel_job
@@ -49,15 +56,17 @@
puts "\nCtrl-C received! Just wait a moment while I clean up..."
cancel_job
end
def publish
+ exit_status = SPEC_SUCCESS_EXIT_STATUS
+
@logger = OriginatorLogger.new configuration[:originator_log_file]
if files.empty?
$stderr.puts "There are no files to test! Quitting."
- exit 2
+ exit ERROR_EXIT_STATUS
end
cluster_id = callback_handler.before_originate
push_source_code
@@ -66,19 +75,20 @@
EventMachine.run do
publish_files_and_job
@protocol.receive_payloads do |payload|
- handle_reply(payload)
+ exit_status |= handle_reply(payload)
end
@protocol.receive_new_listener_notifications do |payload|
handle_new_listener_notification(payload)
end
end
callback_handler.after_job_finishes
+ exit_status
end
def publish_files_and_job
@logger.log "Connecting..."
@protocol.connect connection_information, :on_closed => method(:on_disconnect)
@@ -103,11 +113,11 @@
@logger.log "Command '#{syncer.sys_command}' completed successfully."
else
$stderr.puts "Command '#{syncer.sys_command}' failed!"
$stderr.puts "Stdout:\n#{syncer.output}"
$stderr.puts "Stderr:\n#{syncer.errors}"
- exit 1
+ exit SYNC_ERROR_EXIT_STATUS
end
end
def cleanup_if_job_complete
if @job_state.is_job_complete?
@@ -136,10 +146,11 @@
@logger.log_message payload
# Uncomment this to see each message received by originator
# ap payload
cleanup_if_job_complete
+ exit_status(payload)
end
def handle_new_listener_notification(payload)
payload = Yajl::Parser.new(:symbolize_keys => true).parse(payload)
@@ -178,9 +189,14 @@
job_config[:sync][:source_tree_path] = source_tree_path(job_config[:sync])
JobDefinition.new(configuration[:job])
end
private
+
+ def exit_status(payload)
+ return SPEC_FAILURE_EXIT_STATUS if ["crash", "exception", "fail"].include?(payload[:type])
+ SPEC_SUCCESS_EXIT_STATUS
+ end
def sync_configuration
configuration[:job].
fetch(:sync, {}).
merge(source_tree_path: source_tree_path(configuration[:job][:sync])