{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/comments/123283672","pull_request_review_id":45464176,"id":123283672,"diff_hunk":"@@ -24,18 +30,107 @@ class Command(BaseCommand):\n     help = \"Rebuild the LMS' cache of program data.\"\n \n     def handle(self, *args, **options):\n-        catalog_integration = CatalogIntegration.current()\n-        username = catalog_integration.service_username\n+        if not waffle.switch_is_active(\"populate-multitenant-programs\"):\n+            catalog_integration = CatalogIntegration.current()\n+            username = catalog_integration.service_username\n \n-        try:\n-            user = User.objects.get(username=username)\n-            client = create_catalog_api_client(user)\n-        except User.DoesNotExist:\n-            logger.error(\n-                'Failed to create API client. Service user {username} does not exist.'.format(username)\n-            )\n-            raise\n+            try:\n+                user = User.objects.get(username=username)\n+                client = create_catalog_api_client(user)\n+            except User.DoesNotExist:\n+                logger.error(\n+                    'Failed to create API client. Service user {username} does not exist.'.format(username)\n+                )\n+                raise\n+\n+            try:\n+                querystring = {\n+                    'exclude_utm': 1,\n+                    'status': ('active', 'retired'),\n+                    'uuids_only': 1,\n+                }\n+\n+                logger.info('Requesting program UUIDs.')\n+                uuids = client.programs.get(**querystring)\n+            except:  # pylint: disable=bare-except\n+                logger.error('Failed to retrieve program UUIDs.')\n+                raise\n+\n+            total = len(uuids)\n+            logger.info('Received {total} UUIDs.'.format(total=total))\n+\n+            programs = {}\n+            failure = False\n+            for uuid in uuids:\n+                try:\n+                    logger.info('Requesting details for program {uuid}.'.format(uuid=uuid))\n+                    program = client.programs(uuid).get(exclude_utm=1)\n+\n+                    cache_key = PROGRAM_CACHE_KEY_TPL.format(uuid=uuid)\n+                    programs[cache_key] = program\n+                except:  # pylint: disable=bare-except\n+                    logger.exception('Failed to retrieve details for program {uuid}.'.format(uuid=uuid))\n+                    failure = True\n+\n+                    continue\n+\n+            successful = len(programs)\n+            logger.info('Caching details for {successful} programs.'.format(successful=successful))\n+            cache.set_many(programs, None)\n+\n+            logger.info('Caching UUIDs for {total} programs.'.format(total=total))\n+            cache.set(PROGRAM_UUIDS_CACHE_KEY, uuids, None)\n \n+            if failure:\n+                # This will fail a Jenkins job running this command, letting site\n+                # operators know that there was a problem.\n+                sys.exit(1)\n+\n+        else:\n+            failure = False\n+            logger.info('populate-multitenant-programs switch is ON')\n+\n+            catalog_integration = CatalogIntegration.current()\n+            username = catalog_integration.service_username\n+\n+            try:\n+                user = User.objects.get(username=username)\n+            except User.DoesNotExist:\n+                logger.error(\n+                    'Failed to create API client. Service user {username} does not exist.'.format(username)\n+                )\n+                raise\n+\n+            programs = {}\n+            for site in Site.objects.all():\n+                if not hasattr(site, \"configuration\") or not site.configuration.get_value(\"COURSE_CATALOG_API_URL\"):\n+                    logger.info('Skipping site {sitename}. No configuration.'.format(sitename=site.domain))\n+                    continue\n+\n+                logger.info('trying site {sitename}'.format(sitename=site.domain))\n+                client = create_catalog_api_client(user, site=site)\n+                uuids = self.get_site_program_uuids(client, site)\n+\n+                failure = self.fetch_program_details(client, site, uuids, programs)\n+\n+                logger.info('Caching UUIDs for {total} programs for site {site_name}. key = {cache_key}'.format(","path":"openedx/core/djangoapps/catalog/management/commands/cache_programs.py","position":116,"original_position":116,"commit_id":"cc2869d12823cfe433dbc73c07ad4415fb961ba2","original_commit_id":"cc2869d12823cfe433dbc73c07ad4415fb961ba2","user":{"login":"rlucioni","id":969289,"avatar_url":"https://avatars2.githubusercontent.com/u/969289?v=3","gravatar_id":"","url":"https://api.github.com/users/rlucioni","html_url":"https://github.com/rlucioni","followers_url":"https://api.github.com/users/rlucioni/followers","following_url":"https://api.github.com/users/rlucioni/following{/other_user}","gists_url":"https://api.github.com/users/rlucioni/gists{/gist_id}","starred_url":"https://api.github.com/users/rlucioni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rlucioni/subscriptions","organizations_url":"https://api.github.com/users/rlucioni/orgs","repos_url":"https://api.github.com/users/rlucioni/repos","events_url":"https://api.github.com/users/rlucioni/events{/privacy}","received_events_url":"https://api.github.com/users/rlucioni/received_events","type":"User","site_admin":false},"body":"Remove `key = ...` from this message. It's not necessary.","created_at":"2017-06-21T15:30:54Z","updated_at":"2017-06-21T15:59:04Z","html_url":"https://github.com/edx/edx-platform/pull/15334#discussion_r123283672","pull_request_url":"https://api.github.com/repos/edx/edx-platform/pulls/15334","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments/123283672"},"html":{"href":"https://github.com/edx/edx-platform/pull/15334#discussion_r123283672"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/15334"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-platform/pulls/15334","id":125841832,"html_url":"https://github.com/edx/edx-platform/pull/15334","diff_url":"https://github.com/edx/edx-platform/pull/15334.diff","patch_url":"https://github.com/edx/edx-platform/pull/15334.patch","issue_url":"https://api.github.com/repos/edx/edx-platform/issues/15334","number":15334,"state":"open","locked":false,"title":"Learner-1146","user":{"login":"afzaledx","id":9654006,"avatar_url":"https://avatars3.githubusercontent.com/u/9654006?v=3","gravatar_id":"","url":"https://api.github.com/users/afzaledx","html_url":"https://github.com/afzaledx","followers_url":"https://api.github.com/users/afzaledx/followers","following_url":"https://api.github.com/users/afzaledx/following{/other_user}","gists_url":"https://api.github.com/users/afzaledx/gists{/gist_id}","starred_url":"https://api.github.com/users/afzaledx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/afzaledx/subscriptions","organizations_url":"https://api.github.com/users/afzaledx/orgs","repos_url":"https://api.github.com/users/afzaledx/repos","events_url":"https://api.github.com/users/afzaledx/events{/privacy}","received_events_url":"https://api.github.com/users/afzaledx/received_events","type":"User","site_admin":false},"body":"","created_at":"2017-06-15T14:58:05Z","updated_at":"2017-06-21T15:59:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1cd8d004d750e7c9c977114cc8e5d6211ddaf62f","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-platform/pulls/15334/commits","review_comments_url":"https://api.github.com/repos/edx/edx-platform/pulls/15334/comments","review_comment_url":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-platform/issues/15334/comments","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/cc2869d12823cfe433dbc73c07ad4415fb961ba2","head":{"label":"edx:afzaledx/Learner-1146","ref":"afzaledx/Learner-1146","sha":"cc2869d12823cfe433dbc73c07ad4415fb961ba2","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars0.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars0.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2017-06-21T14:46:56Z","pushed_at":"2017-06-21T15:57:43Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":822719,"stargazers_count":3188,"watchers_count":3188,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1842,"mirror_url":null,"open_issues_count":182,"forks":1842,"open_issues":182,"watchers":3188,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"2b4fb4fd95c1bfebf1d29cfece3627ccbd176165","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars0.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":10391073,"name":"edx-platform","full_name":"edx/edx-platform","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars0.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-platform","description":"The Open edX platform, the software that powers edX!","fork":false,"url":"https://api.github.com/repos/edx/edx-platform","forks_url":"https://api.github.com/repos/edx/edx-platform/forks","keys_url":"https://api.github.com/repos/edx/edx-platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-platform/teams","hooks_url":"https://api.github.com/repos/edx/edx-platform/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-platform/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-platform/events","assignees_url":"https://api.github.com/repos/edx/edx-platform/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-platform/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-platform/tags","blobs_url":"https://api.github.com/repos/edx/edx-platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-platform/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-platform/languages","stargazers_url":"https://api.github.com/repos/edx/edx-platform/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-platform/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-platform/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-platform/subscription","commits_url":"https://api.github.com/repos/edx/edx-platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-platform/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-platform/merges","archive_url":"https://api.github.com/repos/edx/edx-platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-platform/downloads","issues_url":"https://api.github.com/repos/edx/edx-platform/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-platform/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-platform/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-platform/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-platform/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-platform/deployments","created_at":"2013-05-30T20:20:38Z","updated_at":"2017-06-21T14:46:56Z","pushed_at":"2017-06-21T15:57:43Z","git_url":"git://github.com/edx/edx-platform.git","ssh_url":"git@github.com:edx/edx-platform.git","clone_url":"https://github.com/edx/edx-platform.git","svn_url":"https://github.com/edx/edx-platform","homepage":"http://open.edx.org/","size":822719,"stargazers_count":3188,"watchers_count":3188,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1842,"mirror_url":null,"open_issues_count":182,"forks":1842,"open_issues":182,"watchers":3188,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/15334"},"html":{"href":"https://github.com/edx/edx-platform/pull/15334"},"issue":{"href":"https://api.github.com/repos/edx/edx-platform/issues/15334"},"comments":{"href":"https://api.github.com/repos/edx/edx-platform/issues/15334/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/15334/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-platform/pulls/15334/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-platform/statuses/cc2869d12823cfe433dbc73c07ad4415fb961ba2"}}}}
{"actor":{"display_login":"rlucioni"}}