{"action":"created","comment":{"url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/comments/91527496","pull_request_review_id":12036526,"id":91527496,"diff_hunk":"@@ -45,4 +45,86 @@ namespace :pvb do\n       vs.update_column(:visitor_id, vs.visit.principal_visitor.id)\n     end\n   end\n+\n+  # rubocop:disable Metrics/MethodLength\n+  # rubocop:disable Lint/AssignmentInCondition\n+  # rubocop:disable Style/RescueModifier\n+  def check_prisoner_details(client, number, dob)\n+    RequestStore.store[:custom_log_items] = {}\n+    log = { noms_id: number }\n+\n+    begin\n+      response = client.get('/lookup/active_offender',\n+        noms_id: number,\n+        date_of_birth: dob)\n+\n+      log[:found] = !!response['found']\n+    rescue Nomis::APIError => e\n+      log[:error] = e.message\n+    end\n+\n+    log[:timing] = RequestStore.store[:custom_log_items][:api]\n+    log\n+  end\n+\n+  def new_worker(pool, queue, thread_number)\n+    Thread.new do\n+      request_id = \"check_prisoner_details_#{thread_number}\"\n+      RequestStore.store[:request_id] = request_id\n+\n+      begin\n+        while job = queue.pop(true) rescue nil\n+          number, dob = job\n+          pool.with do |client|\n+            STDOUT.print check_prisoner_details(client, number, dob).to_json + \"\\n\"\n+          end\n+        end\n+      rescue ThreadError => e\n+        error_msg = { thread_error: true, message: e.message }.to_json\n+        STDOUT.print error_msg + \"\\n\"\n+      end\n+    end\n+  end\n+  # rubocop:enable Metrics/MethodLength\n+  # rubocop:enable Lint/AssignmentInCondition\n+  # rubocop:enable Style/RescueModifier\n+\n+  desc 'Check vists prisoner details in Nomis'\n+  task check_prisoner_details: :environment do\n+    require 'highline'\n+    require 'instrumentation'\n+\n+    cli = HighLine.new\n+\n+    to_private_key = lambda do |str|\n+      der = Base64.decode64(str)\n+      OpenSSL::PKey::EC.new(der)\n+    end\n+\n+    nomis_key = cli.ask('Nomis api key: ', to_private_key) { |q|\n+      q.echo = '*'\n+    }\n+\n+    nomis_token = cli.ask('Nomis token: ') { |q| q.echo = '*' }\n+\n+    nomis_host = cli.ask('Nomis host: ')\n+    days_to_check = cli.ask('Number of days to check: ', Integer)\n+\n+    data = Prisoner.\n+           where('created_at > ?', days_to_check.days.ago).\n+           pluck(:number, :date_of_birth).\n+           uniq\n+\n+    queue = Queue.new","path":"lib/tasks/one_off.rake","position":74,"original_position":74,"commit_id":"d9a897a2b0375a4375db4e88cbc4906a89fb432a","original_commit_id":"d9a897a2b0375a4375db4e88cbc4906a89fb432a","user":{"login":"StupidCodeFactory","id":100796,"avatar_url":"https://avatars.githubusercontent.com/u/100796?v=3","gravatar_id":"","url":"https://api.github.com/users/StupidCodeFactory","html_url":"https://github.com/StupidCodeFactory","followers_url":"https://api.github.com/users/StupidCodeFactory/followers","following_url":"https://api.github.com/users/StupidCodeFactory/following{/other_user}","gists_url":"https://api.github.com/users/StupidCodeFactory/gists{/gist_id}","starred_url":"https://api.github.com/users/StupidCodeFactory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/StupidCodeFactory/subscriptions","organizations_url":"https://api.github.com/users/StupidCodeFactory/orgs","repos_url":"https://api.github.com/users/StupidCodeFactory/repos","events_url":"https://api.github.com/users/StupidCodeFactory/events{/privacy}","received_events_url":"https://api.github.com/users/StupidCodeFactory/received_events","type":"User","site_admin":false},"body":"👍 ","created_at":"2016-12-08T14:50:32Z","updated_at":"2016-12-08T14:50:32Z","html_url":"https://github.com/ministryofjustice/prison-visits-2/pull/645#discussion_r91527496","pull_request_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/645","_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/comments/91527496"},"html":{"href":"https://github.com/ministryofjustice/prison-visits-2/pull/645#discussion_r91527496"},"pull_request":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/645"}}},"pull_request":{"url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/645","id":97133429,"html_url":"https://github.com/ministryofjustice/prison-visits-2/pull/645","diff_url":"https://github.com/ministryofjustice/prison-visits-2/pull/645.diff","patch_url":"https://github.com/ministryofjustice/prison-visits-2/pull/645.patch","issue_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues/645","number":645,"state":"open","locked":false,"title":"Verify past prisoner details in Nomis","user":{"login":"alan","id":6356,"avatar_url":"https://avatars.githubusercontent.com/u/6356?v=3","gravatar_id":"","url":"https://api.github.com/users/alan","html_url":"https://github.com/alan","followers_url":"https://api.github.com/users/alan/followers","following_url":"https://api.github.com/users/alan/following{/other_user}","gists_url":"https://api.github.com/users/alan/gists{/gist_id}","starred_url":"https://api.github.com/users/alan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alan/subscriptions","organizations_url":"https://api.github.com/users/alan/orgs","repos_url":"https://api.github.com/users/alan/repos","events_url":"https://api.github.com/users/alan/events{/privacy}","received_events_url":"https://api.github.com/users/alan/received_events","type":"User","site_admin":false},"body":"Reads in the Nomis API configuration and the number of days of most recent\r\nprisoners to check and prints out json entry for each prisoner check saying if\r\nit was found or had and error.\r\n\r\nBy reading the Nomis API configuration we should be able to test in production\r\nbefore configuring the server.","created_at":"2016-12-08T14:39:37Z","updated_at":"2016-12-08T14:50:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1ffc53cff8d0b6e654ac44d812b890c032fe080b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/645/commits","review_comments_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/645/comments","review_comment_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues/645/comments","statuses_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/statuses/d9a897a2b0375a4375db4e88cbc4906a89fb432a","head":{"label":"ministryofjustice:verify-prisoner-details-script","ref":"verify-prisoner-details-script","sha":"d9a897a2b0375a4375db4e88cbc4906a89fb432a","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":44737633,"name":"prison-visits-2","full_name":"ministryofjustice/prison-visits-2","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/prison-visits-2","description":"Staff interface and internal API for prison visits service","fork":false,"url":"https://api.github.com/repos/ministryofjustice/prison-visits-2","forks_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/forks","keys_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/events","assignees_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/merges","archive_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/releases{/id}","deployments_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/deployments","created_at":"2015-10-22T10:12:32Z","updated_at":"2016-10-24T10:05:08Z","pushed_at":"2016-12-08T14:40:00Z","git_url":"git://github.com/ministryofjustice/prison-visits-2.git","ssh_url":"git@github.com:ministryofjustice/prison-visits-2.git","clone_url":"https://github.com/ministryofjustice/prison-visits-2.git","svn_url":"https://github.com/ministryofjustice/prison-visits-2","homepage":"","size":2661,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":4,"default_branch":"master"}},"base":{"label":"ministryofjustice:master","ref":"master","sha":"4dc202f2bef9e372e30536b2e33da329f0664028","user":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"repo":{"id":44737633,"name":"prison-visits-2","full_name":"ministryofjustice/prison-visits-2","owner":{"login":"ministryofjustice","id":2203574,"avatar_url":"https://avatars.githubusercontent.com/u/2203574?v=3","gravatar_id":"","url":"https://api.github.com/users/ministryofjustice","html_url":"https://github.com/ministryofjustice","followers_url":"https://api.github.com/users/ministryofjustice/followers","following_url":"https://api.github.com/users/ministryofjustice/following{/other_user}","gists_url":"https://api.github.com/users/ministryofjustice/gists{/gist_id}","starred_url":"https://api.github.com/users/ministryofjustice/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ministryofjustice/subscriptions","organizations_url":"https://api.github.com/users/ministryofjustice/orgs","repos_url":"https://api.github.com/users/ministryofjustice/repos","events_url":"https://api.github.com/users/ministryofjustice/events{/privacy}","received_events_url":"https://api.github.com/users/ministryofjustice/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ministryofjustice/prison-visits-2","description":"Staff interface and internal API for prison visits service","fork":false,"url":"https://api.github.com/repos/ministryofjustice/prison-visits-2","forks_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/forks","keys_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/teams","hooks_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/hooks","issue_events_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues/events{/number}","events_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/events","assignees_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/assignees{/user}","branches_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/branches{/branch}","tags_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/tags","blobs_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/refs{/sha}","trees_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/statuses/{sha}","languages_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/languages","stargazers_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/stargazers","contributors_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/contributors","subscribers_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/subscribers","subscription_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/subscription","commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/commits{/sha}","git_commits_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/git/commits{/sha}","comments_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/comments{/number}","issue_comment_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues/comments{/number}","contents_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/contents/{+path}","compare_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/merges","archive_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/downloads","issues_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues{/number}","pulls_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls{/number}","milestones_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/milestones{/number}","notifications_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/labels{/name}","releases_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/releases{/id}","deployments_url":"https://api.github.com/repos/ministryofjustice/prison-visits-2/deployments","created_at":"2015-10-22T10:12:32Z","updated_at":"2016-10-24T10:05:08Z","pushed_at":"2016-12-08T14:40:00Z","git_url":"git://github.com/ministryofjustice/prison-visits-2.git","ssh_url":"git@github.com:ministryofjustice/prison-visits-2.git","clone_url":"https://github.com/ministryofjustice/prison-visits-2.git","svn_url":"https://github.com/ministryofjustice/prison-visits-2","homepage":"","size":2661,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":6,"forks":0,"open_issues":6,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/645"},"html":{"href":"https://github.com/ministryofjustice/prison-visits-2/pull/645"},"issue":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues/645"},"comments":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/issues/645/comments"},"review_comments":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/645/comments"},"review_comment":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/pulls/645/commits"},"statuses":{"href":"https://api.github.com/repos/ministryofjustice/prison-visits-2/statuses/d9a897a2b0375a4375db4e88cbc4906a89fb432a"}}}}
{"actor":{"display_login":"StupidCodeFactory"}}