New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
alert if we run low on codes #19532
alert if we run low on codes #19532
Conversation
first | ||
limit(20) | ||
|
||
if codes.length < 20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure length
is the right call here? It looks like size
might be a better choice.
limit(20) | ||
|
||
if codes.length < 20 | ||
Honeybadger.notify("Fewer than 20 remaining circuit playground discount codes", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call looks right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, without an error (exception) object, the call is slightly different in order to get it to show up the way we expect. This will work, but I don't think the message will show up in the expected place. @drewsamnick and I went through this recently and came up with this
code-dot-org/dashboard/app/models/school_info.rb
Lines 116 to 122 in e9a1b2c
Honeybadger.notify( | |
error_message: "Overwriting passed in data for new SchoolInfo", | |
error_class: "SchoolInfo.sync_from_schools", | |
context: { | |
original_input: original, | |
school_id: school.id | |
} |
The main difference is you want to add an error_class
, which here is just an arbitrary string, and explicitly specify that the supplied message here is an error_message
.
If you want, you can test this by setting up a personal honeybadger project and logging there from development. I did that a couple years ago when I set up the cronjob-honeybadger logging (aka cronbadger).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize I sent you examples that supplied a rescued error, so those were slightly misleading in this context.
This has now been tested. For future reference my steps were:
|
@@ -20,11 +20,23 @@ def self.claim(full_discount) | |||
|
|||
code = nil | |||
Retryable.retryable(on: ActiveRecord::RecordNotSaved) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this cause an infinite loop if the update_all
fails? In particular, does this cause us to repeatedly notify HB? Perhaps a number of retries should be specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retryable.retryable defaults to 2 tries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, useful to know. LGTM.
If we start to run low on discount codes, make sure HoneyBadger lets us know about it.
Not too sure of the best way of testing this. I made sure that things still work on my local env, but of course can't validate the HB error itself. Presumably I could test this on staging (and maybe staging-next) by using my one-off script to create < 20 fake codes.