{"action":"created","comment":{"url":"https://api.github.com/repos/brave-intl/publishers/pulls/comments/155647959","pull_request_review_id":81985585,"id":155647959,"diff_hunk":"@@ -0,0 +1,30 @@\n+class CleanStalledUpholdCodesAndAccessParametersJob < ApplicationJob\n+  queue_as :scheduler\n+\n+  def perform\n+    # clear uphold codes sitting for over 5 minutes   \n+    publishers = Publisher.has_stalled_uphold_code\n+    n = 0\n+    publishers.each do |publisher|\n+      raise if publisher.uphold_status != :code_acquired\n+      publisher.uphold_code = nil\n+      publisher.uphold_updated_at = Time.now\n+      publisher.save!\n+      n += 1\n+      Rails.logger.info(\"Cleaned stalled uphold code for #{publisher.brave_publisher_id}.\")","path":"app/jobs/clean_stalled_uphold_codes_and_access_parameters_job.rb","position":14,"original_position":14,"commit_id":"aa4f62765f2095e15926a233587b4326224ec689","original_commit_id":"aa4f62765f2095e15926a233587b4326224ec689","user":{"login":"ayumi","id":521861,"avatar_url":"https://avatars1.githubusercontent.com/u/521861?v=4","gravatar_id":"","url":"https://api.github.com/users/ayumi","html_url":"https://github.com/ayumi","followers_url":"https://api.github.com/users/ayumi/followers","following_url":"https://api.github.com/users/ayumi/following{/other_user}","gists_url":"https://api.github.com/users/ayumi/gists{/gist_id}","starred_url":"https://api.github.com/users/ayumi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ayumi/subscriptions","organizations_url":"https://api.github.com/users/ayumi/orgs","repos_url":"https://api.github.com/users/ayumi/repos","events_url":"https://api.github.com/users/ayumi/events{/privacy}","received_events_url":"https://api.github.com/users/ayumi/received_events","type":"User","site_admin":false},"body":"- We should log the publisher.id\r\n- Also I think we should send events to Sentry ([Raven.capture_message](https://docs.sentry.io/clients/ruby/usage/#optional-attributes)) to become aware of the extent of this issue; then we'll review in the medium future.","created_at":"2017-12-07T21:36:15Z","updated_at":"2017-12-07T21:37:33Z","html_url":"https://github.com/brave-intl/publishers/pull/366#discussion_r155647959","pull_request_url":"https://api.github.com/repos/brave-intl/publishers/pulls/366","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/brave-intl/publishers/pulls/comments/155647959"},"html":{"href":"https://github.com/brave-intl/publishers/pull/366#discussion_r155647959"},"pull_request":{"href":"https://api.github.com/repos/brave-intl/publishers/pulls/366"}}},"pull_request":{"url":"https://api.github.com/repos/brave-intl/publishers/pulls/366","id":157072682,"html_url":"https://github.com/brave-intl/publishers/pull/366","diff_url":"https://github.com/brave-intl/publishers/pull/366.diff","patch_url":"https://github.com/brave-intl/publishers/pull/366.patch","issue_url":"https://api.github.com/repos/brave-intl/publishers/issues/366","number":366,"state":"open","locked":false,"title":"Create background job to clean up stalled uphold codes and access params","user":{"login":"nvonpentz","id":12549658,"avatar_url":"https://avatars1.githubusercontent.com/u/12549658?v=4","gravatar_id":"","url":"https://api.github.com/users/nvonpentz","html_url":"https://github.com/nvonpentz","followers_url":"https://api.github.com/users/nvonpentz/followers","following_url":"https://api.github.com/users/nvonpentz/following{/other_user}","gists_url":"https://api.github.com/users/nvonpentz/gists{/gist_id}","starred_url":"https://api.github.com/users/nvonpentz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvonpentz/subscriptions","organizations_url":"https://api.github.com/users/nvonpentz/orgs","repos_url":"https://api.github.com/users/nvonpentz/repos","events_url":"https://api.github.com/users/nvonpentz/events{/privacy}","received_events_url":"https://api.github.com/users/nvonpentz/received_events","type":"User","site_admin":false},"body":"Resolves #224\r\n\r\n### Changes\r\n* Create migration for publisher `uphold_updated_at`\r\n\r\n* Set `uphold_updated_at` on all changes in the Uphold registration flow\r\n\r\n* Add two scopes to Publisher model, `:has_stalled_uphold_code` and `:has_stalled_access_params`\r\n\r\n* Add CleanStalledUpholdCodesAndAccessParametersJob that filters by these scopes and removes stalled codes/access params, logs\r\n\r\n* Tell sidekiq to run this job at 4am every day\r\n\r\n* Add tests for the cleaning job\r\n\r\n* Append logic to existing tests in publishers controller that verify the job runs correctly\r\n\r\n### Discussion\r\nI'm hoping for feedback on these points in addition to other criticism:\r\n\r\n- How frequently should we run the background job?  Currently runs once a day at 4am.\r\n\r\n- Should we log the ID of each publisher who's codes are cleaned, or just the number of codes cleaned? Currently it does both.\r\n\r\n- Should we use a `private` method within the CleanStalledUpholdCodesAndAccessParametersJob class to create the filters instead of the scopes on the model `:has_stalled_uphold_code` and `:has_stalled_uphold_access_parameters`?\r\n\r\nSubmitter Checklist:\r\n\r\n- [x] Submitted a [ticket](https://github.com/brave-intl/publishers/issues) for my issue if one did not already exist.\r\n- [x] Used Github [auto-closing keywords](https://help.github.com/articles/closing-issues-via-commit-messages/) in the commit message.\r\n- [x] Added/updated tests for this change (for new code or code which already has tests).\r\n- [x] Tagged reviewers.\r\n\r\nTest Plan:\r\nI added tests for the job that verify codes/params are removed if five minutes have passed (codes) or two hours have passed (params), and not if otherwise.  The model validations do a lot of the work for us.\r\n\r\nI also ran the job and added a check at the end of two existing tests in the publishers controller to better simulate real world conditions.\r\n\r\nReviewer Checklist:\r\n\r\nTests\r\n- [ ] Adequate test coverage exists to prevent regressions\r\n\r\nSecurity:\r\n- [ ] No raw SQL -- Always prefer ActiveRecord query helpers ([more info on StackOverflow](https://stackoverflow.com/questions/41410752/rails-5-sql-injection#41452695))\r\n- [ ] XSS is mitigated -- Avoid `html_safe` and `raw`; escape untrusted content from users and 3rd party APIs ([Rails XSS guide](https://brakemanpro.com/2017/09/08/cross-site-scripting-in-rails) and [OWASP XSS Prevention Cheat Sheet](https://www.owasp.org/index.php/XSS_(Cross_Site_Scripting)_Prevention_Cheat_Sheet))\r\n","created_at":"2017-12-07T18:48:40Z","updated_at":"2017-12-07T21:37:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"feb0447b448cc86442d5119c9247b8b9dcbc26a8","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/brave-intl/publishers/pulls/366/commits","review_comments_url":"https://api.github.com/repos/brave-intl/publishers/pulls/366/comments","review_comment_url":"https://api.github.com/repos/brave-intl/publishers/pulls/comments{/number}","comments_url":"https://api.github.com/repos/brave-intl/publishers/issues/366/comments","statuses_url":"https://api.github.com/repos/brave-intl/publishers/statuses/aa4f62765f2095e15926a233587b4326224ec689","head":{"label":"nvonpentz:clean-stalled-uphold-codes-and-params","ref":"clean-stalled-uphold-codes-and-params","sha":"aa4f62765f2095e15926a233587b4326224ec689","user":{"login":"nvonpentz","id":12549658,"avatar_url":"https://avatars1.githubusercontent.com/u/12549658?v=4","gravatar_id":"","url":"https://api.github.com/users/nvonpentz","html_url":"https://github.com/nvonpentz","followers_url":"https://api.github.com/users/nvonpentz/followers","following_url":"https://api.github.com/users/nvonpentz/following{/other_user}","gists_url":"https://api.github.com/users/nvonpentz/gists{/gist_id}","starred_url":"https://api.github.com/users/nvonpentz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvonpentz/subscriptions","organizations_url":"https://api.github.com/users/nvonpentz/orgs","repos_url":"https://api.github.com/users/nvonpentz/repos","events_url":"https://api.github.com/users/nvonpentz/events{/privacy}","received_events_url":"https://api.github.com/users/nvonpentz/received_events","type":"User","site_admin":false},"repo":{"id":111492596,"name":"publishers","full_name":"nvonpentz/publishers","owner":{"login":"nvonpentz","id":12549658,"avatar_url":"https://avatars1.githubusercontent.com/u/12549658?v=4","gravatar_id":"","url":"https://api.github.com/users/nvonpentz","html_url":"https://github.com/nvonpentz","followers_url":"https://api.github.com/users/nvonpentz/followers","following_url":"https://api.github.com/users/nvonpentz/following{/other_user}","gists_url":"https://api.github.com/users/nvonpentz/gists{/gist_id}","starred_url":"https://api.github.com/users/nvonpentz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nvonpentz/subscriptions","organizations_url":"https://api.github.com/users/nvonpentz/orgs","repos_url":"https://api.github.com/users/nvonpentz/repos","events_url":"https://api.github.com/users/nvonpentz/events{/privacy}","received_events_url":"https://api.github.com/users/nvonpentz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nvonpentz/publishers","description":"Publisher interface for Brave Payments","fork":true,"url":"https://api.github.com/repos/nvonpentz/publishers","forks_url":"https://api.github.com/repos/nvonpentz/publishers/forks","keys_url":"https://api.github.com/repos/nvonpentz/publishers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nvonpentz/publishers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nvonpentz/publishers/teams","hooks_url":"https://api.github.com/repos/nvonpentz/publishers/hooks","issue_events_url":"https://api.github.com/repos/nvonpentz/publishers/issues/events{/number}","events_url":"https://api.github.com/repos/nvonpentz/publishers/events","assignees_url":"https://api.github.com/repos/nvonpentz/publishers/assignees{/user}","branches_url":"https://api.github.com/repos/nvonpentz/publishers/branches{/branch}","tags_url":"https://api.github.com/repos/nvonpentz/publishers/tags","blobs_url":"https://api.github.com/repos/nvonpentz/publishers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nvonpentz/publishers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nvonpentz/publishers/git/refs{/sha}","trees_url":"https://api.github.com/repos/nvonpentz/publishers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nvonpentz/publishers/statuses/{sha}","languages_url":"https://api.github.com/repos/nvonpentz/publishers/languages","stargazers_url":"https://api.github.com/repos/nvonpentz/publishers/stargazers","contributors_url":"https://api.github.com/repos/nvonpentz/publishers/contributors","subscribers_url":"https://api.github.com/repos/nvonpentz/publishers/subscribers","subscription_url":"https://api.github.com/repos/nvonpentz/publishers/subscription","commits_url":"https://api.github.com/repos/nvonpentz/publishers/commits{/sha}","git_commits_url":"https://api.github.com/repos/nvonpentz/publishers/git/commits{/sha}","comments_url":"https://api.github.com/repos/nvonpentz/publishers/comments{/number}","issue_comment_url":"https://api.github.com/repos/nvonpentz/publishers/issues/comments{/number}","contents_url":"https://api.github.com/repos/nvonpentz/publishers/contents/{+path}","compare_url":"https://api.github.com/repos/nvonpentz/publishers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nvonpentz/publishers/merges","archive_url":"https://api.github.com/repos/nvonpentz/publishers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nvonpentz/publishers/downloads","issues_url":"https://api.github.com/repos/nvonpentz/publishers/issues{/number}","pulls_url":"https://api.github.com/repos/nvonpentz/publishers/pulls{/number}","milestones_url":"https://api.github.com/repos/nvonpentz/publishers/milestones{/number}","notifications_url":"https://api.github.com/repos/nvonpentz/publishers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nvonpentz/publishers/labels{/name}","releases_url":"https://api.github.com/repos/nvonpentz/publishers/releases{/id}","deployments_url":"https://api.github.com/repos/nvonpentz/publishers/deployments","created_at":"2017-11-21T03:12:22Z","updated_at":"2017-11-21T03:12:25Z","pushed_at":"2017-12-07T18:42:26Z","git_url":"git://github.com/nvonpentz/publishers.git","ssh_url":"git@github.com:nvonpentz/publishers.git","clone_url":"https://github.com/nvonpentz/publishers.git","svn_url":"https://github.com/nvonpentz/publishers","homepage":"https://publishers.brave.com","size":7630,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"staging"}},"base":{"label":"brave-intl:staging","ref":"staging","sha":"4b6575c8fb6b1f104f8a879802dc9c7fb40e2e70","user":{"login":"brave-intl","id":28767864,"avatar_url":"https://avatars2.githubusercontent.com/u/28767864?v=4","gravatar_id":"","url":"https://api.github.com/users/brave-intl","html_url":"https://github.com/brave-intl","followers_url":"https://api.github.com/users/brave-intl/followers","following_url":"https://api.github.com/users/brave-intl/following{/other_user}","gists_url":"https://api.github.com/users/brave-intl/gists{/gist_id}","starred_url":"https://api.github.com/users/brave-intl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brave-intl/subscriptions","organizations_url":"https://api.github.com/users/brave-intl/orgs","repos_url":"https://api.github.com/users/brave-intl/repos","events_url":"https://api.github.com/users/brave-intl/events{/privacy}","received_events_url":"https://api.github.com/users/brave-intl/received_events","type":"Organization","site_admin":false},"repo":{"id":69634519,"name":"publishers","full_name":"brave-intl/publishers","owner":{"login":"brave-intl","id":28767864,"avatar_url":"https://avatars2.githubusercontent.com/u/28767864?v=4","gravatar_id":"","url":"https://api.github.com/users/brave-intl","html_url":"https://github.com/brave-intl","followers_url":"https://api.github.com/users/brave-intl/followers","following_url":"https://api.github.com/users/brave-intl/following{/other_user}","gists_url":"https://api.github.com/users/brave-intl/gists{/gist_id}","starred_url":"https://api.github.com/users/brave-intl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brave-intl/subscriptions","organizations_url":"https://api.github.com/users/brave-intl/orgs","repos_url":"https://api.github.com/users/brave-intl/repos","events_url":"https://api.github.com/users/brave-intl/events{/privacy}","received_events_url":"https://api.github.com/users/brave-intl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/brave-intl/publishers","description":"Publisher interface for Brave Payments","fork":false,"url":"https://api.github.com/repos/brave-intl/publishers","forks_url":"https://api.github.com/repos/brave-intl/publishers/forks","keys_url":"https://api.github.com/repos/brave-intl/publishers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/brave-intl/publishers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/brave-intl/publishers/teams","hooks_url":"https://api.github.com/repos/brave-intl/publishers/hooks","issue_events_url":"https://api.github.com/repos/brave-intl/publishers/issues/events{/number}","events_url":"https://api.github.com/repos/brave-intl/publishers/events","assignees_url":"https://api.github.com/repos/brave-intl/publishers/assignees{/user}","branches_url":"https://api.github.com/repos/brave-intl/publishers/branches{/branch}","tags_url":"https://api.github.com/repos/brave-intl/publishers/tags","blobs_url":"https://api.github.com/repos/brave-intl/publishers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/brave-intl/publishers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/brave-intl/publishers/git/refs{/sha}","trees_url":"https://api.github.com/repos/brave-intl/publishers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/brave-intl/publishers/statuses/{sha}","languages_url":"https://api.github.com/repos/brave-intl/publishers/languages","stargazers_url":"https://api.github.com/repos/brave-intl/publishers/stargazers","contributors_url":"https://api.github.com/repos/brave-intl/publishers/contributors","subscribers_url":"https://api.github.com/repos/brave-intl/publishers/subscribers","subscription_url":"https://api.github.com/repos/brave-intl/publishers/subscription","commits_url":"https://api.github.com/repos/brave-intl/publishers/commits{/sha}","git_commits_url":"https://api.github.com/repos/brave-intl/publishers/git/commits{/sha}","comments_url":"https://api.github.com/repos/brave-intl/publishers/comments{/number}","issue_comment_url":"https://api.github.com/repos/brave-intl/publishers/issues/comments{/number}","contents_url":"https://api.github.com/repos/brave-intl/publishers/contents/{+path}","compare_url":"https://api.github.com/repos/brave-intl/publishers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/brave-intl/publishers/merges","archive_url":"https://api.github.com/repos/brave-intl/publishers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/brave-intl/publishers/downloads","issues_url":"https://api.github.com/repos/brave-intl/publishers/issues{/number}","pulls_url":"https://api.github.com/repos/brave-intl/publishers/pulls{/number}","milestones_url":"https://api.github.com/repos/brave-intl/publishers/milestones{/number}","notifications_url":"https://api.github.com/repos/brave-intl/publishers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/brave-intl/publishers/labels{/name}","releases_url":"https://api.github.com/repos/brave-intl/publishers/releases{/id}","deployments_url":"https://api.github.com/repos/brave-intl/publishers/deployments","created_at":"2016-09-30T04:47:29Z","updated_at":"2017-11-29T04:47:51Z","pushed_at":"2017-12-07T21:33:46Z","git_url":"git://github.com/brave-intl/publishers.git","ssh_url":"git@github.com:brave-intl/publishers.git","clone_url":"https://github.com/brave-intl/publishers.git","svn_url":"https://github.com/brave-intl/publishers","homepage":"https://publishers.brave.com","size":7625,"stargazers_count":11,"watchers_count":11,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"archived":false,"open_issues_count":36,"license":{"key":"mpl-2.0","name":"Mozilla Public License 2.0","spdx_id":"MPL-2.0","url":"https://api.github.com/licenses/mpl-2.0"},"forks":12,"open_issues":36,"watchers":11,"default_branch":"staging"}},"_links":{"self":{"href":"https://api.github.com/repos/brave-intl/publishers/pulls/366"},"html":{"href":"https://github.com/brave-intl/publishers/pull/366"},"issue":{"href":"https://api.github.com/repos/brave-intl/publishers/issues/366"},"comments":{"href":"https://api.github.com/repos/brave-intl/publishers/issues/366/comments"},"review_comments":{"href":"https://api.github.com/repos/brave-intl/publishers/pulls/366/comments"},"review_comment":{"href":"https://api.github.com/repos/brave-intl/publishers/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/brave-intl/publishers/pulls/366/commits"},"statuses":{"href":"https://api.github.com/repos/brave-intl/publishers/statuses/aa4f62765f2095e15926a233587b4326224ec689"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"ayumi"}}