Class: Listener
Constant Summary
CrashReporter::OUTPUT_LINES_TO_REPORT
Constants included
from GLogger
GLogger::SIZE_1_MB
Instance Method Summary
collapse
#report_crash, #send_crash_message
Methods included from GLogger
#initialize_logger, #log, #log_error
#load_configuration_from_file
Constructor Details
Returns a new instance of Listener.
23
24
25
26
27
28
29
30
|
# File 'lib/gorgon/listener.rb', line 23
def initialize
@listener_config_filename = Dir.pwd + "/gorgon_listener.json"
initialize_logger configuration[:log_file]
log "Listener #{Gorgon::VERSION} initializing"
connect
initialize_personal_job_queue
end
|
Instance Method Details
#at_exit_hook ⇒ Object
94
95
96
|
# File 'lib/gorgon/listener.rb', line 94
def at_exit_hook
at_exit { log "Listener will exit!"}
end
|
#connect ⇒ Object
40
41
42
43
|
# File 'lib/gorgon/listener.rb', line 40
def connect
@bunny = GorgonBunny.new(connection_information)
@bunny.start
end
|
#handle_request(json_payload) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/gorgon/listener.rb', line 64
def handle_request json_payload
payload = Yajl::Parser.new(:symbolize_keys => true).parse(json_payload)
case payload[:type]
when "job_definition"
run_job(payload)
when "ping"
respond_to_ping payload[:reply_exchange_name]
when "gem_command"
GemCommandHandler.new(@bunny).handle payload, configuration
end
end
|
#initialize_personal_job_queue ⇒ Object
45
46
47
48
49
|
# File 'lib/gorgon/listener.rb', line 45
def initialize_personal_job_queue
@job_queue = @bunny.queue("", :exclusive => true)
exchange = @bunny.exchange("gorgon.jobs", :type => :fanout)
@job_queue.bind(exchange)
end
|
#listen ⇒ Object
32
33
34
35
36
37
38
|
# File 'lib/gorgon/listener.rb', line 32
def listen
at_exit_hook
log "Waiting for jobs..."
while true
sleep 2 unless poll
end
end
|
#poll ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/gorgon/listener.rb', line 51
def poll
message = @job_queue.pop
return false if message == [nil, nil, nil]
log "Received: #{message}"
payload = message[2]
handle_request payload
log "Waiting for more jobs..."
return true
end
|
#run_job(payload) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/gorgon/listener.rb', line 77
def run_job(payload)
@job_definition = JobDefinition.new(payload)
@reply_exchange = @bunny.exchange(@job_definition.reply_exchange_name, :auto_delete => true)
@callback_handler = CallbackHandler.new(@job_definition.callbacks)
copy_source_tree(@job_definition.source_tree_path, @job_definition.sync_exclude)
if !@syncer.success? || !run_after_sync
clean_up
return
end
fork_worker_manager
clean_up
end
|