9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/legion/api/capacity.rb', line 9
def self.registered(app)
app.get '/api/capacity' do
workers = Routes::Capacity.fetch_worker_list
model = Legion::Capacity::Model.new(workers: workers)
json_response(model.aggregate)
rescue StandardError => e
Legion::Logging.error "API GET /api/capacity: #{e.class} — #{e.message}"
json_error('capacity_error', e.message, status_code: 500)
end
app.get '/api/capacity/forecast' do
workers = Routes::Capacity.fetch_worker_list
model = Legion::Capacity::Model.new(workers: workers)
forecast = model.forecast(
days: (params[:days] || 30).to_i,
growth_rate: (params[:growth_rate] || 0).to_f
)
json_response(forecast)
rescue StandardError => e
Legion::Logging.error "API GET /api/capacity/forecast: #{e.class} — #{e.message}"
json_error('capacity_error', e.message, status_code: 500)
end
app.get '/api/capacity/workers' do
workers = Routes::Capacity.fetch_worker_list
model = Legion::Capacity::Model.new(workers: workers)
json_response(model.per_worker_stats)
rescue StandardError => e
Legion::Logging.error "API GET /api/capacity/workers: #{e.class} — #{e.message}"
json_error('capacity_error', e.message, status_code: 500)
end
end
|