3 ms·
Here's a choice piece of code we have in production along the lines of what you suggest: if prorated_amount > (cost_per_month * 2) raise "critical! w
by aculver 13y ago
Here's a choice piece of code we have in production along the lines of what you suggest:
if prorated_amount > (cost_per_month * 2)
raise "critical! we were about to prorate-charge someone #{prorated_amount}"
end
It's never been triggered, but this is probably the only place in our system where we're actually responsible for an exact amount that ends up on an invoice, so having a reasonable upper limit seems like a no-brainer.
- ronaldx 13y agoshouldn't it be >=, to catch double-charging?
- hartleybrody 13y agoWhat if this code is called multiple times in quick succession? Based on the fact that I got a dozen separate emails over the span of 10 minutes, I'm guessing Twilio's overcharging happened in a series of transactions, not all at once. This code -- while good for catching bad single calculations -- wouldn't catch that.
- wizzard 13y agoWell I don't think he was saying "cut and paste this exact code into your codebase" but rather that it is possible to write safeguards such as this... in this case, perhaps checking whether an account has already been billed this month, or whether there is already a transaction pending, or... We can't prevent every mistake but we can make sure the same one doesn't happen again.