This commit adds feature of sending alerts when the total consumption exceeds a user-defined threshold. We associate each alert to a user who created it and send the email to that user when the alert is triggered. An alternative would be allowing users to specify an email address to send the alert to, but that opens an attack vector where a user could spam another user with alerts. This vector can be mitigated by requiring the user to confirm the email address, but implementing a whole confirmation workflow would significantly increase the effort required to implement this feature.
16 lines
386 B
Ruby
16 lines
386 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Prog::CheckUsageAlerts < Prog::Base
|
|
label def wait
|
|
begin_time = Date.new(Time.now.year, Time.now.month, 1).to_time
|
|
|
|
alerts = UsageAlert.where { last_triggered_at < begin_time }
|
|
alerts.each do |alert|
|
|
cost = alert.project.current_invoice.content["cost"]
|
|
alert.trigger if cost > alert.limit
|
|
end
|
|
|
|
nap 5 * 60
|
|
end
|
|
end
|