Class: FileProcessingJob::Client::Connection
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- FileProcessingJob::Client::Connection
- Includes:
- AASM
- Defined in:
- lib/fpj/client.rb
Class Attribute Summary collapse
-
.callback ⇒ Object
Returns the value of attribute callback.
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
- #download_file ⇒ Object
- #logger ⇒ Object
- #post_init ⇒ Object
- #process_file ⇒ Object
- #receive_data(data) ⇒ Object
- #request_task ⇒ Object
Class Attribute Details
.callback ⇒ Object
Returns the value of attribute callback.
22 23 24 |
# File 'lib/fpj/client.rb', line 22 def callback @callback end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
25 26 27 |
# File 'lib/fpj/client.rb', line 25 def data @data end |
#filename ⇒ Object
Returns the value of attribute filename.
25 26 27 |
# File 'lib/fpj/client.rb', line 25 def filename @filename end |
Instance Method Details
#download_file ⇒ Object
59 60 61 62 |
# File 'lib/fpj/client.rb', line 59 def download_file self.filename = self.data send_data "get #{self.filename}" end |
#logger ⇒ Object
48 49 50 |
# File 'lib/fpj/client.rb', line 48 def logger FileProcessingJob.logger end |
#post_init ⇒ Object
75 76 77 |
# File 'lib/fpj/client.rb', line 75 def post_init request_task end |
#process_file ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fpj/client.rb', line 64 def process_file begin self.class.callback.new.send(:receive_file, self.data) send_data "processed #{self.filename}" rescue logger.error("Error processing #{self.filename}. The file can be found on the server in the 'error' directory") logger.error($!) send_data "error #{self.filename}" end end |
#receive_data(data) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/fpj/client.rb', line 79 def receive_data(data) self.data = data case aasm_current_state when :requesting_task filename_received when :downloading file_received when :processing file_processed next_task end end |
#request_task ⇒ Object
53 54 55 56 57 |
# File 'lib/fpj/client.rb', line 53 def request_task self.filename = nil self.data = nil send_data "next" end |