LG-15655: Submit reCAPTCHA annotations through worker job (Part 2 of 2)#11926
LG-15655: Submit reCAPTCHA annotations through worker job (Part 2 of 2)#11926
Conversation
changelog: Internal, Anti-Fraud Tooling, Submit reCAPTCHA annotations through worker job
mdiarra3
left a comment
There was a problem hiding this comment.
Looks good. Tested this locally and worked as expected. Had a recaptcha assessment stored in db too.
Actually, this reminds me I'd originally wondered if it would make sense to delete the record after it's submitted successfully, as a sort of auto-cleanup for the table, since we don't need it any more 🤔 |
Already tested with coverage on RecaptchaAnnotator#submit_assessment
I pushed changes for this in ebc7d1e. |
Originally considered approach deleting the record inside the annotator class
app/jobs/recaptcha_annotate_job.rb
Outdated
| class RecaptchaAnnotateJob < ApplicationJob | ||
| def perform(assessment:) | ||
| RecaptchaAnnotator.submit_assessment(assessment) | ||
| assessment.destroy |
There was a problem hiding this comment.
Noting that these changes would only be effective for half of the worker instances in the 50/50 state, therefore some stale assessments could remain. That might be acceptable, since this is just a clean-up of unnecessary data, but the other option would be to split out a separate pull request with just these changes to deploy before the main pull request.
A third option could be to move the deletion into the RecaptchaAnnotator class. I wasn't originally a fan of that because it feels like the annotator's job should be to just submit the annotation, but maybe it fits the scope of "annotating" to include the clean-up of the assessment record, and keeps the job implementation lean. Pragmatically, it would also avoid having to deal with these issues or a third pull request.
There was a problem hiding this comment.
Actually, the third option might still be best, but it doesn't actually work around the 50/50 state, since the new application instances would schedule the job from RecaptchaAnnotator, but the actual submission in RecaptchaAnnotator would still happen in a (possibly-old) worker instance.
There was a problem hiding this comment.
Based on a conversation in Slack, I added timestamps to the table in be44d95, which should more easily allow us to delete any stale data in the future.
| add_timestamps :recaptcha_assessments | ||
| change_column_comment :recaptcha_assessments, :created_at, from: nil, to: 'sensitive=false' | ||
| change_column_comment :recaptcha_assessments, :updated_at, from: nil, to: 'sensitive=false' |
There was a problem hiding this comment.
Normally I would have expected to be able to add the comment as part of the add_timestamps call:
| add_timestamps :recaptcha_assessments | |
| change_column_comment :recaptcha_assessments, :created_at, from: nil, to: 'sensitive=false' | |
| change_column_comment :recaptcha_assessments, :updated_at, from: nil, to: 'sensitive=false' | |
| add_timestamps :recaptcha_assessments, comment: 'sensitive=false' |
But this was causing an error during migration, and it looks like the SQL query was including a stringified Ruby proc. Maybe a bug with add_timestamps? I had even tried it with a change_table { |t| t.add_timestamps ... } and got the same result.
ALTER TABLE "recaptcha_assessments" ADD "created_at" timestamp(6) NOT NULL, #<Proc:0x00000001476d1120 /gems/activerecord-8.0.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:1048>, ADD "updated_at" timestamp(6) NOT NULL, #<Proc:0x00000001476d0d38 /gems/activerecord-8.0.1/lib/active_record/connection_adapters/postgresql/schema_statements.rb:1048>
🎫 Ticket
LG-15655
🛠 Summary of changes
Updates
RecaptchaAnnotatorto asynchronously schedule a worker job to perform the annotation later.It also removes the feature flag controlling whether to submit annotations for reCAPTCHA assessments performed at sign-in, effectively enabling the behavior everywhere. This is because the asynchronous annotations behavior was the blocker for enabling the behavior, and therefore is satisfied by the changes to
RecaptchaAnnotator.This builds upon:
📜 Testing Plan
Repeat Testing Plan from #11883, noting that you will not have to replace commented code, since those are the changes being implemented in this pull request.