{"action":"created","comment":{"url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/comments/202612647","pull_request_review_id":137344084,"id":202612647,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMjYxMjY0Nw==","diff_hunk":"@@ -0,0 +1,127 @@\n+import * as winston from \"winston\";\n+import * as documentDbUtils from \"../lib/utils/documentdb\";\n+\n+import { IContext } from \"azure-function-express\";\n+import { DocumentClient } from \"documentdb\";\n+import { isLeft } from \"fp-ts/lib/Either\";\n+import { isNone, isSome } from \"fp-ts/lib/Option\";\n+import { pick } from \"italia-ts-commons/lib/types\";\n+import { RetrievedService } from \"./models/service\";\n+import {\n+  VISIBLE_SERVICE_COLLECTION_NAME,\n+  VisibleServiceModel\n+} from \"./models/visible_service\";\n+import { getRequiredStringEnv } from \"./utils/env\";\n+import { PermanentError } from \"./utils/errors\";\n+import { configureAzureContextTransport } from \"./utils/logging\";\n+\n+// Whether we're in a production environment\n+const isProduction = process.env.NODE_ENV === \"production\";\n+\n+const cosmosDbUri = getRequiredStringEnv(\"CUSTOMCONNSTR_COSMOSDB_URI\");\n+const cosmosDbKey = getRequiredStringEnv(\"CUSTOMCONNSTR_COSMOSDB_KEY\");\n+const cosmosDbName = getRequiredStringEnv(\"COSMOSDB_NAME\");\n+\n+const documentDbDatabaseUrl = documentDbUtils.getDatabaseUri(cosmosDbName);\n+\n+const visibleServicesCollectionUrl = documentDbUtils.getCollectionUri(\n+  documentDbDatabaseUrl,\n+  VISIBLE_SERVICE_COLLECTION_NAME\n+);\n+const documentClient = new DocumentClient(cosmosDbUri, {\n+  masterKey: cosmosDbKey\n+});\n+\n+const visibleServiceModel = new VisibleServiceModel(\n+  documentClient,\n+  visibleServicesCollectionUrl\n+);\n+\n+/**\n+ * A function to cache the list of visible (active) services.\n+ * Reacts to CosmosDB changes (change feed) in the services collection.\n+ */\n+export async function index(\n+  context: IContext<{}>,\n+  documents: ReadonlyArray<RetrievedService>\n+): Promise<void> {\n+  const logLevel = isProduction ? \"info\" : \"debug\";\n+  configureAzureContextTransport(context, winston, logLevel);\n+\n+  try {\n+    documents.forEach(async createdOrUpdatedService => {\n+      winston.debug(\n+        \"ComputeVisibleService: %s\",\n+        JSON.stringify(createdOrUpdatedService)\n+      );\n+      const errorOrMaybeVisibleService = await visibleServiceModel.find(\n+        createdOrUpdatedService.id,\n+        createdOrUpdatedService.serviceId\n+      );\n+      if (isLeft(errorOrMaybeVisibleService)) {\n+        winston.debug(\n+          \"ComputeVisibleService Query Error: %s\",\n+          JSON.stringify(errorOrMaybeVisibleService.value)\n+        );\n+        return PermanentError(\"QueryError querying for visible service\");","path":"lib/compute_visible_services.ts","position":66,"original_position":66,"commit_id":"188307471b2bc422408f3c552c1ee061e1ab349e","original_commit_id":"188307471b2bc422408f3c552c1ee061e1ab349e","user":{"login":"gunzip","id":148224,"node_id":"MDQ6VXNlcjE0ODIyNA==","avatar_url":"https://avatars2.githubusercontent.com/u/148224?v=4","gravatar_id":"","url":"https://api.github.com/users/gunzip","html_url":"https://github.com/gunzip","followers_url":"https://api.github.com/users/gunzip/followers","following_url":"https://api.github.com/users/gunzip/following{/other_user}","gists_url":"https://api.github.com/users/gunzip/gists{/gist_id}","starred_url":"https://api.github.com/users/gunzip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gunzip/subscriptions","organizations_url":"https://api.github.com/users/gunzip/orgs","repos_url":"https://api.github.com/users/gunzip/repos","events_url":"https://api.github.com/users/gunzip/events{/privacy}","received_events_url":"https://api.github.com/users/gunzip/received_events","type":"User","site_admin":false},"body":"yes, if you trigger an exception here the events will be rescheduled using the default functions configurations (a burst of fast re-processing). \r\n\r\nthis function is triggered by a cosmosdb change feed event which cannot be re-scheduled (if not re-saving the service inside the services collection). we may schedule \"inner\" retries but this will stretch the function runtime.","created_at":"2018-07-16T08:59:35Z","updated_at":"2018-07-16T08:59:36Z","html_url":"https://github.com/teamdigitale/digital-citizenship-functions/pull/312#discussion_r202612647","pull_request_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/312","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/comments/202612647"},"html":{"href":"https://github.com/teamdigitale/digital-citizenship-functions/pull/312#discussion_r202612647"},"pull_request":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/312"}},"in_reply_to_id":202548493},"pull_request":{"url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/312","id":201446471,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAxNDQ2NDcx","html_url":"https://github.com/teamdigitale/digital-citizenship-functions/pull/312","diff_url":"https://github.com/teamdigitale/digital-citizenship-functions/pull/312.diff","patch_url":"https://github.com/teamdigitale/digital-citizenship-functions/pull/312.patch","issue_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues/312","number":312,"state":"open","locked":false,"title":"[#158967411] [WIP] add endpoint to retrieve all visibile services","user":{"login":"gunzip","id":148224,"node_id":"MDQ6VXNlcjE0ODIyNA==","avatar_url":"https://avatars2.githubusercontent.com/u/148224?v=4","gravatar_id":"","url":"https://api.github.com/users/gunzip","html_url":"https://github.com/gunzip","followers_url":"https://api.github.com/users/gunzip/followers","following_url":"https://api.github.com/users/gunzip/following{/other_user}","gists_url":"https://api.github.com/users/gunzip/gists{/gist_id}","starred_url":"https://api.github.com/users/gunzip/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gunzip/subscriptions","organizations_url":"https://api.github.com/users/gunzip/orgs","repos_url":"https://api.github.com/users/gunzip/repos","events_url":"https://api.github.com/users/gunzip/events{/privacy}","received_events_url":"https://api.github.com/users/gunzip/received_events","type":"User","site_admin":false},"body":"- adds an endpoint (controller method) to list all visbile services\r\n- adds visibile_service model\r\n- adds is_visible flag to services\r\n- adds a new function to compute the list of all visible services into a news cosmosdb collection (reacts to cosmosdb change feed -> updates / inserts from services colleoction)\r\n- incorporates some documentdb fixes from #311\r\n\r\nWIP as it lacks tests but the logic is complete\r\n","created_at":"2018-07-14T10:40:51Z","updated_at":"2018-07-16T08:59:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"afeb34a2217d1d511b26e43dfc29859d51016d6a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/312/commits","review_comments_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/312/comments","review_comment_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/comments{/number}","comments_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues/312/comments","statuses_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/statuses/188307471b2bc422408f3c552c1ee061e1ab349e","head":{"label":"teamdigitale:158967411-service-list-real","ref":"158967411-service-list-real","sha":"188307471b2bc422408f3c552c1ee061e1ab349e","user":{"login":"teamdigitale","id":25081492,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MDgxNDky","avatar_url":"https://avatars0.githubusercontent.com/u/25081492?v=4","gravatar_id":"","url":"https://api.github.com/users/teamdigitale","html_url":"https://github.com/teamdigitale","followers_url":"https://api.github.com/users/teamdigitale/followers","following_url":"https://api.github.com/users/teamdigitale/following{/other_user}","gists_url":"https://api.github.com/users/teamdigitale/gists{/gist_id}","starred_url":"https://api.github.com/users/teamdigitale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teamdigitale/subscriptions","organizations_url":"https://api.github.com/users/teamdigitale/orgs","repos_url":"https://api.github.com/users/teamdigitale/repos","events_url":"https://api.github.com/users/teamdigitale/events{/privacy}","received_events_url":"https://api.github.com/users/teamdigitale/received_events","type":"Organization","site_admin":false},"repo":{"id":98789853,"node_id":"MDEwOlJlcG9zaXRvcnk5ODc4OTg1Mw==","name":"digital-citizenship-functions","full_name":"teamdigitale/digital-citizenship-functions","owner":{"login":"teamdigitale","id":25081492,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MDgxNDky","avatar_url":"https://avatars0.githubusercontent.com/u/25081492?v=4","gravatar_id":"","url":"https://api.github.com/users/teamdigitale","html_url":"https://github.com/teamdigitale","followers_url":"https://api.github.com/users/teamdigitale/followers","following_url":"https://api.github.com/users/teamdigitale/following{/other_user}","gists_url":"https://api.github.com/users/teamdigitale/gists{/gist_id}","starred_url":"https://api.github.com/users/teamdigitale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teamdigitale/subscriptions","organizations_url":"https://api.github.com/users/teamdigitale/orgs","repos_url":"https://api.github.com/users/teamdigitale/repos","events_url":"https://api.github.com/users/teamdigitale/events{/privacy}","received_events_url":"https://api.github.com/users/teamdigitale/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/teamdigitale/digital-citizenship-functions","description":"Digital Citizenship APIs","fork":false,"url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions","forks_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/forks","keys_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/teams","hooks_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/hooks","issue_events_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues/events{/number}","events_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/events","assignees_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/assignees{/user}","branches_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/branches{/branch}","tags_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/tags","blobs_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/refs{/sha}","trees_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/statuses/{sha}","languages_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/languages","stargazers_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/stargazers","contributors_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/contributors","subscribers_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/subscribers","subscription_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/subscription","commits_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/commits{/sha}","git_commits_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/commits{/sha}","comments_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/comments{/number}","issue_comment_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues/comments{/number}","contents_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/contents/{+path}","compare_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/merges","archive_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/downloads","issues_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues{/number}","pulls_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls{/number}","milestones_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/milestones{/number}","notifications_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/labels{/name}","releases_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/releases{/id}","deployments_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/deployments","created_at":"2017-07-30T10:19:53Z","updated_at":"2018-07-13T15:30:58Z","pushed_at":"2018-07-16T04:21:58Z","git_url":"git://github.com/teamdigitale/digital-citizenship-functions.git","ssh_url":"git@github.com:teamdigitale/digital-citizenship-functions.git","clone_url":"https://github.com/teamdigitale/digital-citizenship-functions.git","svn_url":"https://github.com/teamdigitale/digital-citizenship-functions","homepage":"","size":12940,"stargazers_count":4,"watchers_count":4,"language":"TypeScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"archived":false,"open_issues_count":15,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":6,"open_issues":15,"watchers":4,"default_branch":"master"}},"base":{"label":"teamdigitale:master","ref":"master","sha":"457532a6716ede9b2be86296beaf52bd2d1bf761","user":{"login":"teamdigitale","id":25081492,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MDgxNDky","avatar_url":"https://avatars0.githubusercontent.com/u/25081492?v=4","gravatar_id":"","url":"https://api.github.com/users/teamdigitale","html_url":"https://github.com/teamdigitale","followers_url":"https://api.github.com/users/teamdigitale/followers","following_url":"https://api.github.com/users/teamdigitale/following{/other_user}","gists_url":"https://api.github.com/users/teamdigitale/gists{/gist_id}","starred_url":"https://api.github.com/users/teamdigitale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teamdigitale/subscriptions","organizations_url":"https://api.github.com/users/teamdigitale/orgs","repos_url":"https://api.github.com/users/teamdigitale/repos","events_url":"https://api.github.com/users/teamdigitale/events{/privacy}","received_events_url":"https://api.github.com/users/teamdigitale/received_events","type":"Organization","site_admin":false},"repo":{"id":98789853,"node_id":"MDEwOlJlcG9zaXRvcnk5ODc4OTg1Mw==","name":"digital-citizenship-functions","full_name":"teamdigitale/digital-citizenship-functions","owner":{"login":"teamdigitale","id":25081492,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI1MDgxNDky","avatar_url":"https://avatars0.githubusercontent.com/u/25081492?v=4","gravatar_id":"","url":"https://api.github.com/users/teamdigitale","html_url":"https://github.com/teamdigitale","followers_url":"https://api.github.com/users/teamdigitale/followers","following_url":"https://api.github.com/users/teamdigitale/following{/other_user}","gists_url":"https://api.github.com/users/teamdigitale/gists{/gist_id}","starred_url":"https://api.github.com/users/teamdigitale/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teamdigitale/subscriptions","organizations_url":"https://api.github.com/users/teamdigitale/orgs","repos_url":"https://api.github.com/users/teamdigitale/repos","events_url":"https://api.github.com/users/teamdigitale/events{/privacy}","received_events_url":"https://api.github.com/users/teamdigitale/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/teamdigitale/digital-citizenship-functions","description":"Digital Citizenship APIs","fork":false,"url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions","forks_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/forks","keys_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/keys{/key_id}","collaborators_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/teams","hooks_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/hooks","issue_events_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues/events{/number}","events_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/events","assignees_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/assignees{/user}","branches_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/branches{/branch}","tags_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/tags","blobs_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/refs{/sha}","trees_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/trees{/sha}","statuses_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/statuses/{sha}","languages_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/languages","stargazers_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/stargazers","contributors_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/contributors","subscribers_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/subscribers","subscription_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/subscription","commits_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/commits{/sha}","git_commits_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/git/commits{/sha}","comments_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/comments{/number}","issue_comment_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues/comments{/number}","contents_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/contents/{+path}","compare_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/compare/{base}...{head}","merges_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/merges","archive_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/downloads","issues_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues{/number}","pulls_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls{/number}","milestones_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/milestones{/number}","notifications_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/labels{/name}","releases_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/releases{/id}","deployments_url":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/deployments","created_at":"2017-07-30T10:19:53Z","updated_at":"2018-07-13T15:30:58Z","pushed_at":"2018-07-16T04:21:58Z","git_url":"git://github.com/teamdigitale/digital-citizenship-functions.git","ssh_url":"git@github.com:teamdigitale/digital-citizenship-functions.git","clone_url":"https://github.com/teamdigitale/digital-citizenship-functions.git","svn_url":"https://github.com/teamdigitale/digital-citizenship-functions","homepage":"","size":12940,"stargazers_count":4,"watchers_count":4,"language":"TypeScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":6,"mirror_url":null,"archived":false,"open_issues_count":15,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":6,"open_issues":15,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/312"},"html":{"href":"https://github.com/teamdigitale/digital-citizenship-functions/pull/312"},"issue":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues/312"},"comments":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/issues/312/comments"},"review_comments":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/312/comments"},"review_comment":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/pulls/312/commits"},"statuses":{"href":"https://api.github.com/repos/teamdigitale/digital-citizenship-functions/statuses/188307471b2bc422408f3c552c1ee061e1ab349e"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"gunzip"}}