Class: Devformance::MetricsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/devformance/metrics_controller.rb

Instance Method Summary collapse

Instance Method Details

#download_logObject



31
32
33
34
35
36
37
38
39
# File 'app/controllers/devformance/metrics_controller.rb', line 31

def download_log
  result = ::Devformance::FileResult.find_by(
    run_id: params[:run_id], file_key: params[:file_key]
  )
  return render plain: "Not found", status: :not_found unless result&.log_path
  return render plain: "Log not ready", status: :not_found unless File.exist?(result.log_path)

  send_file result.log_path, type: "text/plain", disposition: "attachment"
end

#indexObject



5
6
# File 'app/controllers/devformance/metrics_controller.rb', line 5

def index
end

#run_statusObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/devformance/metrics_controller.rb', line 17

def run_status
  run = ::Devformance::Run.find_by(run_id: params[:run_id])
  return render json: { error: "Not found" }, status: :not_found unless run

  render json: {
    run_id: run.run_id,
    status: run.status,
    files:  run.file_results.map { |r|
      { file_key: r.file_key, file_path: r.file_path, status: r.status,
        coverage: r.coverage, slow_query_count: r.slow_query_count, n1_count: r.n1_count }
    }
  }
end

#run_testsObject



8
9
10
11
12
13
14
15
# File 'app/controllers/devformance/metrics_controller.rb', line 8

def run_tests
  result = ::Devformance::RunOrchestrator.call
  if result[:error]
    render json: { error: result[:error] }, status: :unprocessable_entity
  else
    render json: result, status: :accepted
  end
end