Class: Diffend::Track
- Inherits:
-
Object
- Object
- Diffend::Track
- 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
- #build_request_object(request_id) ⇒ Diffend::RequestObject
-
#exec_request ⇒ Object
Perform an exec request.
-
#fetch_config ⇒ OpenStruct?
Fetch diffend config file.
-
#initialize ⇒ Track
constructor
Initialize tracking.
- #perform(request_id) ⇒ Object
-
#start ⇒ Object
Start tracking.
-
#track_request(request_id) ⇒ Object
Perform a track request.
- #track_url(project_id, request_id) ⇒ String
Constructor Details
#initialize ⇒ Track
Initialize tracking
12 13 14 15 |
# File 'lib/diffend/track.rb', line 12 def initialize @mutex = Mutex.new @config = fetch_config end |
Instance Method Details
#build_request_object(request_id) ⇒ Diffend::RequestObject
76 77 78 79 80 81 82 83 |
# File 'lib/diffend/track.rb', line 76 def build_request_object(request_id) Diffend::RequestObject.new( config: @config, url: track_url(@config.project_id, request_id), payload: { id: request_id }.freeze, request_method: :put ).freeze end |
#exec_request ⇒ Object
Perform an exec request
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/diffend/track.rb', line 52 def exec_request Diffend::Voting.call( Diffend::Commands::EXEC, @config, Diffend::BuildBundlerDefinition.call( Diffend::Commands::EXEC, Bundler.default_gemfile, Bundler.default_lockfile ) ) end |
#fetch_config ⇒ OpenStruct?
Fetch diffend config file
90 91 92 93 94 |
# File 'lib/diffend/track.rb', line 90 def fetch_config Config::Fetcher.call( File.('..', Bundler.bin_path) ) end |
#perform(request_id) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/diffend/track.rb', line 41 def perform(request_id) loop do @mutex.synchronize do track_request(request_id) end sleep(TRACK_SLEEP) end end |
#start ⇒ Object
Start tracking
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/diffend/track.rb', line 18 def start response = exec_request 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
67 68 69 70 71 |
# File 'lib/diffend/track.rb', line 67 def track_request(request_id) Diffend::Request.call( build_request_object(request_id) ) end |
#track_url(project_id, request_id) ⇒ String
100 101 102 |
# File 'lib/diffend/track.rb', line 100 def track_url(project_id, request_id) "https://my.diffend.io/api/projects/#{project_id}/bundle/#{request_id}/track" end |