Class: FileProcessingJob::Client::Connection

Inherits:
EM::Connection
  • Object
show all
Includes:
AASM
Defined in:
lib/fpj/client.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.callbackObject

Returns the value of attribute callback.



22
23
24
# File 'lib/fpj/client.rb', line 22

def callback
  @callback
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



25
26
27
# File 'lib/fpj/client.rb', line 25

def data
  @data
end

#filenameObject

Returns the value of attribute filename.



25
26
27
# File 'lib/fpj/client.rb', line 25

def filename
  @filename
end

Instance Method Details

#download_fileObject



59
60
61
62
# File 'lib/fpj/client.rb', line 59

def download_file
  self.filename = self.data
  send_data "get #{self.filename}"
end

#loggerObject



48
49
50
# File 'lib/fpj/client.rb', line 48

def logger
  FileProcessingJob.logger
end

#post_initObject



75
76
77
# File 'lib/fpj/client.rb', line 75

def post_init
  request_task
end

#process_fileObject



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_taskObject



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