Class: Diffend::Track

Inherits:
Object
  • Object
show all
Defined in:
lib/diffend/track.rb

Overview

Track what is run in production

Constant Summary collapse

TRACK_SLEEP =

Time that we want to wait between track requests

15
RETRY_SLEEP =

Time that we want to wait before we retry

15

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Track

Initialize tracking

Parameters:



14
15
16
17
# File 'lib/diffend/track.rb', line 14

def initialize(config)
  @mutex = Mutex.new
  @config = config
end

Instance Method Details

#build_request_object(request_id) ⇒ Diffend::RequestObject

Parameters:

  • request_id (String)

Returns:



63
64
65
66
67
68
69
70
# File 'lib/diffend/track.rb', line 63

def build_request_object(request_id)
  Diffend::RequestObject.new(
    @config,
    @config.track_url(request_id),
    { id: request_id }.freeze,
    :put
  ).freeze
end

#perform(request_id) ⇒ Object

Parameters:

  • request_id (String)


43
44
45
46
47
48
49
# File 'lib/diffend/track.rb', line 43

def perform(request_id)
  loop do
    @mutex.synchronize { track_request(request_id) }

    sleep(TRACK_SLEEP)
  end
end

#startObject

Start tracking



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/diffend/track.rb', line 20

def start
  response = Diffend::Execute.call(@config)

  perform(response['id'])
rescue Diffend::Errors::HandledException
  sleep(RETRY_SLEEP)

  retry
rescue StandardError => e
  Diffend::HandleErrors::Report.call(
    exception: e,
    config: @config,
    message: :unhandled_exception,
    report: true,
    raise_exception: false
  )

  sleep(RETRY_SLEEP)

  retry
end

#track_request(request_id) ⇒ Object

Perform a track request

Parameters:

  • request_id (String)


54
55
56
57
58
# File 'lib/diffend/track.rb', line 54

def track_request(request_id)
  Diffend::Request.call(
    build_request_object(request_id)
  )
end