Class: Dev2func::Shipper

Inherits:
Object
  • Object
show all
Defined in:
lib/dev2func/shipper.rb

Constant Summary collapse

DEFAULT_DOMAIN =
'http://localhost:8080'.freeze
DEFAULT_ENDPOINT =
'/api/v1/streams'.freeze
DEFAULT_API_DOMAIN =
'https://stream.dev2func.com'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShipper

Returns a new instance of Shipper.



12
13
14
15
16
17
# File 'lib/dev2func/shipper.rb', line 12

def initialize
  self.faraday = Faraday.new(
    url: DEFAULT_DOMAIN,
    headers: { 'Content-Type' => 'application/json' }
  )
end

Instance Attribute Details

#configurationObject

Returns the value of attribute configuration.



6
7
8
# File 'lib/dev2func/shipper.rb', line 6

def configuration
  @configuration
end

#containerObject

Returns the value of attribute container.



6
7
8
# File 'lib/dev2func/shipper.rb', line 6

def container
  @container
end

#faradayObject

Returns the value of attribute faraday.



6
7
8
# File 'lib/dev2func/shipper.rb', line 6

def faraday
  @faraday
end

#streamObject

Returns the value of attribute stream.



6
7
8
# File 'lib/dev2func/shipper.rb', line 6

def stream
  @stream
end

Instance Method Details

#shipped(container) ⇒ Object

Sending stream to Dev2func API



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dev2func/shipper.rb', line 20

def shipped(container)
  Rails.logger.info "[Dev2func] Ready to ship the container"
  self.container = container
  self.stream = self.container.stream
  self.configuration = self.container.configuration

  Rails.logger.info "[Dev2func] Stream content: #{self.stream}"
  Rails.logger.info "[Dev2func] Container content: #{self.configuration.project_token}"

  response = self.faraday.post("#{DEFAULT_API_DOMAIN}#{DEFAULT_ENDPOINT}") do |req|
    req.body = JSON.generate(
      ruby_version: self.configuration.platform_detail['ruby_version'],
      status: self.stream['status'].to_s,
      error_type: "internal server error", #internal server error,  etc..
      exception_type: self.stream['exception'], # #<StandardError: StandardError>, etc..",
      stream_type: 'errors', # info,errors,warning
      event: self.stream['traces']['Application Trace'].first['trace'],
      projects: {
        project_token: self.configuration.project_token
      },
      # _backtrace = []
      # self.stream['traces']['Framework Trace'].each do |ft|
      #   _backtrace << ft["trace"]
      # end
      backtrace: self.stream['traces']['Framework Trace'].to_s,
      platform_detail: self.configuration.platform_detail.to_s
    )
  end

  Rails.logger.info "status: #{response.status}"
  Rails.logger.info "body: #{response.body}"
  Rails.logger.info "[Dev2func] Success sending container"
end