payload: {"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/content-publisher/pulls/comments/359445441","pull_request_review_id":334097636,"id":359445441,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDM1OTQ0NTQ0MQ==","diff_hunk":"@@ -1,27 +1,31 @@\n # frozen_string_literal: true\n \n module WhitehallImporter\n-  def self.import(whitehall_document)\n-    record = WhitehallImport.create!(\n+  def self.import_and_sync(whitehall_document)\n+    whitehall_import = WhitehallImport.create!(\n       whitehall_document_id: whitehall_document[\"id\"],\n       payload: whitehall_document,\n       content_id: whitehall_document[\"content_id\"],\n       state: \"importing\",\n     )\n \n-    begin\n-      Import.call(whitehall_document)\n-      record.update!(state: \"completed\")\n-    rescue StandardError => e\n-      record.update!(error_log: e.message,\n-                     state: \"import_failed\")\n-    end\n+    import(whitehall_import)\n \n-    record\n+    sync(whitehall_import) if whitehall_import.imported?\n+\n+    whitehall_import\n+  end\n+\n+  def self.import(whitehall_import)\n+    document = Import.call(whitehall_import.payload)\n+    whitehall_import.update!(document: document, state: \"imported\")\n+  rescue StandardError => e\n+    whitehall_import.update!(error_log: e.message, state: \"import_failed\")\n   end\n \n-  def self.sync(document)\n-    ResyncService.call(document)\n-    ClearLinksetLinks.call(document.content_id)\n+  def self.sync(whitehall_import)","path":"lib/whitehall_importer.rb","position":41,"original_position":39,"commit_id":"4189df0312f20b6591bd1361892da0ca9c1b35da","original_commit_id":"8f2a9cce3380ef5d485d72ac5b77f2dc5d216a9b","user":{"login":"kevindew","id":282717,"node_id":"MDQ6VXNlcjI4MjcxNw==","avatar_url":"https://avatars0.githubusercontent.com/u/282717?v=4","gravatar_id":"","url":"https://api.github.com/users/kevindew","html_url":"https://github.com/kevindew","followers_url":"https://api.github.com/users/kevindew/followers","following_url":"https://api.github.com/users/kevindew/following{/other_user}","gists_url":"https://api.github.com/users/kevindew/gists{/gist_id}","starred_url":"https://api.github.com/users/kevindew/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kevindew/subscriptions","organizations_url":"https://api.github.com/users/kevindew/orgs","repos_url":"https://api.github.com/users/kevindew/repos","events_url":"https://api.github.com/users/kevindew/events{/privacy}","received_events_url":"https://api.github.com/users/kevindew/received_events","type":"User","site_admin":false},"body":"I think this depends on whether we consider these methods to be part of the public interface of WhitehallImporter or not.\r\n\r\nWe can mark them as private with `private_class_method` if they're just private. Though I'd expect we'd at least want sync available in case we want to try retry if a sync fails (Bruce and I have been talking about failures and retries today).\r\n\r\nI anticipated we'd want the raises as a sense check since if a whitehall_import is passed to either of these in an unexpected state it causes data inconsistency. For example if you call .import with something that is already imported you'll get it set \"import_failed\" when that is not the case. Similarly if you pass a whitehall_import that is \"importing\" into .sync then it'll end up with a sync_failed status despite having never been imported.","created_at":"2019-12-18T16:32:47Z","updated_at":"2019-12-18T16:32:52Z","html_url":"https://github.com/alphagov/content-publisher/pull/1535#discussion_r359445441","pull_request_url":"https://api.github.com/repos/alphagov/content-publisher/pulls/1535","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/alphagov/content-publisher/pulls/comments/359445441"},"html":{"href":"https://github.com/alphagov/content-publisher/pull/1535#discussion_r359445441"},"pull_request":{"href":"https://api.github.com/repos/alphagov/content-publisher/pulls/1535"}},"in_reply_to_id":359404880},"pull_request":{"url":"https://api.github.com/repos/alphagov/content-publisher/pulls/1535","id":354663022,"node_id":"MDExOlB1bGxSZXF1ZXN0MzU0NjYzMDIy","html_url":"https://github.com/alphagov/content-publisher/pull/1535","diff_url":"https://github.com/alphagov/content-publisher/pull/1535.diff","patch_url":"https://github.com/alphagov/content-publisher/pull/1535.patch","issue_url":"https://api.github.com/repos/alphagov/content-publisher/issues/1535","number":1535,"state":"open","locked":false,"title":"Add more import statuses","user":{"login":"1pretz1","id":24479188,"node_id":"MDQ6VXNlcjI0NDc5MTg4","avatar_url":"https://avatars1.githubusercontent.com/u/24479188?v=4","gravatar_id":"","url":"https://api.github.com/users/1pretz1","html_url":"https://github.com/1pretz1","followers_url":"https://api.github.com/users/1pretz1/followers","following_url":"https://api.github.com/users/1pretz1/following{/other_user}","gists_url":"https://api.github.com/users/1pretz1/gists{/gist_id}","starred_url":"https://api.github.com/users/1pretz1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/1pretz1/subscriptions","organizations_url":"https://api.github.com/users/1pretz1/orgs","repos_url":"https://api.github.com/users/1pretz1/repos","events_url":"https://api.github.com/users/1pretz1/events{/privacy}","received_events_url":"https://api.github.com/users/1pretz1/received_events","type":"User","site_admin":false},"body":"Currently the [WhitehallImport](https://github.com/alphagov/content-publisher/blob/fb45dd1ff913e9ffed8ab59ed4799be033f6eb59/app/models/whitehall_import.rb) has 3 statuses (importing, completed and failed) these are now not sufficient for the amount of things that can happen.\r\n\r\nBelow is the full list of import statuses implemented in this PR:\r\n- importing -> doing the import process\r\n- imported -> importing is complete\r\n- import_aborted -> an AbortImportError is raised during import\r\n- import_failed -> an unexpected error is raised during import\r\n- syncing -> syncing the data with GOV.UK\r\n- sync_failed -> an unexpected error is raised during syncing\r\n- completed -> everything was successful\r\n\r\nRelated PR (separates out the migration which is also used by https://github.com/alphagov/content-publisher/pull/1530):\r\nhttps://github.com/alphagov/content-publisher/pull/1534\r\n\r\nTrello:\r\nhttps://trello.com/c/GbgBv1Nz/1233-track-and-implement-more-statuses-in-whitehall-import-aborted-import-failed-syncing-sync-failed-complete\r\n","created_at":"2019-12-18T15:08:31Z","updated_at":"2019-12-18T16:32:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8781a2ca0523ef1007cf7a832a6b0798b9b39bc2","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/content-publisher/pulls/1535/commits","review_comments_url":"https://api.github.com/repos/alphagov/content-publisher/pulls/1535/comments","review_comment_url":"https://api.github.com/repos/alphagov/content-publisher/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/content-publisher/issues/1535/comments","statuses_url":"https://api.github.com/repos/alphagov/content-publisher/statuses/4189df0312f20b6591bd1361892da0ca9c1b35da","head":{"label":"alphagov:add-more-import-statuses","ref":"add-more-import-statuses","sha":"4189df0312f20b6591bd1361892da0ca9c1b35da","user":{"login":"alphagov","id":596977,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU5Njk3Nw==","avatar_url":"https://avatars0.githubusercontent.com/u/596977?v=4","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":140405637,"node_id":"MDEwOlJlcG9zaXRvcnkxNDA0MDU2Mzc=","name":"content-publisher","full_name":"alphagov/content-publisher","private":false,"owner":{"login":"alphagov","id":596977,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU5Njk3Nw==","avatar_url":"https://avatars0.githubusercontent.com/u/596977?v=4","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/alphagov/content-publisher","description":"Publishing application for GOV.UK ","fork":false,"url":"https://api.github.com/repos/alphagov/content-publisher","forks_url":"https://api.github.com/repos/alphagov/content-publisher/forks","keys_url":"https://api.github.com/repos/alphagov/content-publisher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/content-publisher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/content-publisher/teams","hooks_url":"https://api.github.com/repos/alphagov/content-publisher/hooks","issue_events_url":"https://api.github.com/repos/alphagov/content-publisher/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/content-publisher/events","assignees_url":"https://api.github.com/repos/alphagov/content-publisher/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/content-publisher/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/content-publisher/tags","blobs_url":"https://api.github.com/repos/alphagov/content-publisher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/content-publisher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/content-publisher/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/content-publisher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/content-publisher/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/content-publisher/languages","stargazers_url":"https://api.github.com/repos/alphagov/content-publisher/stargazers","contributors_url":"https://api.github.com/repos/alphagov/content-publisher/contributors","subscribers_url":"https://api.github.com/repos/alphagov/content-publisher/subscribers","subscription_url":"https://api.github.com/repos/alphagov/content-publisher/subscription","commits_url":"https://api.github.com/repos/alphagov/content-publisher/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/content-publisher/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/content-publisher/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/content-publisher/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/content-publisher/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/content-publisher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/content-publisher/merges","archive_url":"https://api.github.com/repos/alphagov/content-publisher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/content-publisher/downloads","issues_url":"https://api.github.com/repos/alphagov/content-publisher/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/content-publisher/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/content-publisher/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/content-publisher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/content-publisher/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/content-publisher/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/content-publisher/deployments","created_at":"2018-07-10T09:00:26Z","updated_at":"2019-12-18T11:43:21Z","pushed_at":"2019-12-18T16:32:15Z","git_url":"git://github.com/alphagov/content-publisher.git","ssh_url":"git@github.com:alphagov/content-publisher.git","clone_url":"https://github.com/alphagov/content-publisher.git","svn_url":"https://github.com/alphagov/content-publisher","homepage":"https://docs.publishing.service.gov.uk/apps/content-publisher.html","size":9007,"stargazers_count":20,"watchers_count":20,"language":"Ruby","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":7,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":5,"open_issues":7,"watchers":20,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"974e6c4ebe91bac9f80468b4b710477032738e4d","user":{"login":"alphagov","id":596977,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU5Njk3Nw==","avatar_url":"https://avatars0.githubusercontent.com/u/596977?v=4","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":140405637,"node_id":"MDEwOlJlcG9zaXRvcnkxNDA0MDU2Mzc=","name":"content-publisher","full_name":"alphagov/content-publisher","private":false,"owner":{"login":"alphagov","id":596977,"node_id":"MDEyOk9yZ2FuaXphdGlvbjU5Njk3Nw==","avatar_url":"https://avatars0.githubusercontent.com/u/596977?v=4","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/alphagov/content-publisher","description":"Publishing application for GOV.UK ","fork":false,"url":"https://api.github.com/repos/alphagov/content-publisher","forks_url":"https://api.github.com/repos/alphagov/content-publisher/forks","keys_url":"https://api.github.com/repos/alphagov/content-publisher/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/content-publisher/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/content-publisher/teams","hooks_url":"https://api.github.com/repos/alphagov/content-publisher/hooks","issue_events_url":"https://api.github.com/repos/alphagov/content-publisher/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/content-publisher/events","assignees_url":"https://api.github.com/repos/alphagov/content-publisher/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/content-publisher/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/content-publisher/tags","blobs_url":"https://api.github.com/repos/alphagov/content-publisher/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/content-publisher/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/content-publisher/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/content-publisher/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/content-publisher/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/content-publisher/languages","stargazers_url":"https://api.github.com/repos/alphagov/content-publisher/stargazers","contributors_url":"https://api.github.com/repos/alphagov/content-publisher/contributors","subscribers_url":"https://api.github.com/repos/alphagov/content-publisher/subscribers","subscription_url":"https://api.github.com/repos/alphagov/content-publisher/subscription","commits_url":"https://api.github.com/repos/alphagov/content-publisher/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/content-publisher/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/content-publisher/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/content-publisher/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/content-publisher/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/content-publisher/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/content-publisher/merges","archive_url":"https://api.github.com/repos/alphagov/content-publisher/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/content-publisher/downloads","issues_url":"https://api.github.com/repos/alphagov/content-publisher/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/content-publisher/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/content-publisher/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/content-publisher/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/content-publisher/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/content-publisher/releases{/id}","deployments_url":"https://api.github.com/repos/alphagov/content-publisher/deployments","created_at":"2018-07-10T09:00:26Z","updated_at":"2019-12-18T11:43:21Z","pushed_at":"2019-12-18T16:32:15Z","git_url":"git://github.com/alphagov/content-publisher.git","ssh_url":"git@github.com:alphagov/content-publisher.git","clone_url":"https://github.com/alphagov/content-publisher.git","svn_url":"https://github.com/alphagov/content-publisher","homepage":"https://docs.publishing.service.gov.uk/apps/content-publisher.html","size":9007,"stargazers_count":20,"watchers_count":20,"language":"Ruby","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":7,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":5,"open_issues":7,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/content-publisher/pulls/1535"},"html":{"href":"https://github.com/alphagov/content-publisher/pull/1535"},"issue":{"href":"https://api.github.com/repos/alphagov/content-publisher/issues/1535"},"comments":{"href":"https://api.github.com/repos/alphagov/content-publisher/issues/1535/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/content-publisher/pulls/1535/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/content-publisher/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/content-publisher/pulls/1535/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/content-publisher/statuses/4189df0312f20b6591bd1361892da0ca9c1b35da"}},"author_association":"CONTRIBUTOR"}}
other: {"actor":{"display_login":"kevindew"}}