Class: FileProcessingJob::Client::Connection
Constant Summary
FileProcessingJob::Connection::TOKEN
Class Attribute Summary collapse
Instance Method Summary
collapse
#initialize, logger, #logger, #receive_data, #receive_request, #send_message
Class Attribute Details
.callback ⇒ Object
Returns the value of attribute callback.
26
27
28
|
# File 'lib/fpj/client.rb', line 26
def callback
@callback
end
|
Instance Method Details
#error(filename) ⇒ Object
33
34
35
|
# File 'lib/fpj/client.rb', line 33
def error(filename)
send_message "error #{filename}"
end
|
#post_init ⇒ Object
48
49
50
|
# File 'lib/fpj/client.rb', line 48
def post_init
request_task
end
|
#process(filename, contents) ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/fpj/client.rb', line 37
def process(filename, contents)
begin
self.class.callback.new.send(:receive_file, filename, contents)
send_message "processed #{filename}"
rescue
logger.error("Error processing #{filename}. The file can be found on the server in the 'error' directory")
logger.error($!)
error(filename)
end
end
|
#receive_task(data) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/fpj/client.rb', line 56
def receive_task(data)
if (data =~ /^filename: (.*)/)
@filename = $1
else
@contents = data
end
if (@filename && @contents)
logger.info "Processing #{@filename}"
process(@filename, @contents)
end
end
|
#request_task ⇒ Object
29
30
31
|
# File 'lib/fpj/client.rb', line 29
def request_task
send_message('next')
end
|
#unbind ⇒ Object
52
53
54
|
# File 'lib/fpj/client.rb', line 52
def unbind
EventMachine::stop_event_loop
end
|