-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplan.rb
More file actions
46 lines (38 loc) · 1.15 KB
/
plan.rb
File metadata and controls
46 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
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
41
42
43
44
45
46
# frozen_string_literal: true
module Travis
module Scheduler
module Jobs
module Capacity
class Plan < Base
def applicable?
on_metered_plan? || owners.subscribed?
end
def report(status, job)
super.merge(max:)
end
def accept?(job)
super if !on_metered_plan? || billing_allowed?(job)
end
private
def max
@max ||= on_metered_plan? ? billing_allowance['concurrency_limit'] : owners.paid_capacity
end
def billing_allowed?(job)
puts billing_allowance[allowance_key(job)]
return true if billing_allowance[allowance_key(job)]
# Cancel job if it has not been queued for more than a day due to
# billing allowance
if job.created_at < (Time.now - 1.day)
payload = { id: job.id, source: 'scheduler' }
Hub.push('job:cancel', payload)
end
false
end
def allowance_key(job)
job.public? ? 'public_repos' : 'private_repos'
end
end
end
end
end
end