{"action":"created","comment":{"url":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/comments/175215688","pull_request_review_id":104719515,"id":175215688,"diff_hunk":"@@ -310,19 +318,133 @@ def make_parser(self):\n                 \"Example Usage: --only=riak,stanchion\"\n             )\n         )\n+        self.parser.add_argument(\n+            '--worker_name',\n+            help=(\n+                \"Celery worker name as appearing in the status list. \"\n+                \"This can also be a comma-separated list of workers\"\n+                \"For ex: Run 'commcare-cloud staging celery status' to get name of workers\"\n+            )\n+        )\n \n     def get_inventory_group_for_service(self, service, service_group):\n         return self.INVENTORY_GROUP_FOR_SERVICE.get(service, service_group)\n \n+    @staticmethod\n+    def _get_celery_processes(env):\n+        environment = get_environment(env)\n+        app_processes_config = environment.translated_app_processes_config\n+        return app_processes_config.celery_processes\n+\n+    def get_celery_config(self, args):\n+        environment = get_environment(args.environment)\n+        project_name = environment.fab_settings_config.project\n+        \"\"\"\n+        This picks the logic from set_celery_supervisorconf to produce the full worker names\n+        as declared in the template supervisor_celery_worker.conf\n+        {{ project }}-{{ environment }}-celery_{{ celery_params.comma_separated_queue_names }}_{{ celery_params.worker_num }}\n+        :return:\n+        celery_worker_config: a worker name mapped to list for full worker names per host\n+        {'submission_reprocessing_queue':\n+          {'hqcelery0.internal-va.commcarehq.org':\n+            ['commcare-hq-production-celery_submission_reprocessing_queue_0']\n+          }\n+        },\n+        \"\"\"\n+        celery_worker_config = {}\n+        celery_processes = self._get_celery_processes(args.environment)\n+        for host, celery_processes_list in celery_processes.items():\n+            if host != 'None':\n+                for worker_name, details in celery_processes_list.items():\n+                    # split comma separated names to individual workers\n+                    for worker in worker_name.split(','):\n+                        # ignore flower and celery periodic as celery workers\n+                        if worker not in ['flower', 'celery_periodic']:\n+                            if not celery_worker_config.get(worker):\n+                                celery_worker_config[worker] = defaultdict(list)\n+\n+                            if details.get('num_workers', 1) > 2:\n+                                for num in range(details.get('num_workers')):\n+                                    full_worker_name = \"%s-%s-celery_%s_%s\" % (\n+                                        project_name, args.environment, worker_name, num\n+                                    )\n+                                    celery_worker_config[worker][host].append(full_worker_name)\n+                            else:\n+                                full_worker_name = \"%s-%s-celery_%s_%s\" % (\n+                                    project_name, args.environment, worker_name, 0\n+                                )\n+                                celery_worker_config[worker][host].append(full_worker_name)\n+        return celery_worker_config\n+\n+    def get_workers_to_work_on(self, args):\n+        \"\"\"\n+        :return:\n+        workers_by_host: full name of workers per host to work on\n+        \"\"\"\n+        celery_config = self.get_celery_config(args)\n+        # full name of workers per host to run an action on\n+        workers_by_host = defaultdict(list)\n+        if args.worker_name:\n+            for worker_name in args.worker_name.split(','):\n+                if worker_name not in celery_config:\n+                    puts(colored.red(\n+                        \"%s not found in the list of possible worker names, %s\" % (\n+                            worker_name, celery_config.keys()\n+                        )))\n+                    raise\n+                for host, full_worker_names in celery_config[worker_name].items():\n+                    workers_by_host[host].extend(full_worker_names)\n+        else:\n+            for worker_name in celery_config:\n+                for host, full_worker_names in celery_config[worker_name].items():\n+                    workers_by_host[host].extend(full_worker_names)\n+        return workers_by_host\n+\n+    def run_for_celery(self, service_group, action, args, unknown_args):\n+        exit_code = 0\n+        service = \"celery\"\n+        if action == \"status\" and not args.worker_name:\n+            args.shell_command = \"supervisorctl %s\" % action\n+            args.inventory_group = self.get_inventory_group_for_service(service, args.service_group)\n+            exit_code = RunShellCommand(self.parser).run(args, unknown_args)\n+        else:\n+            try:\n+                workers_by_host = self.get_workers_to_work_on(args)\n+            except Exception:","path":"commcare-cloud/commcare_cloud/commands/ansible/ansible_playbook.py","position":null,"original_position":127,"commit_id":"b6a3d6a0da50a9fce1e9518734177ded64f5f413","original_commit_id":"a060c850ed1c1474aada904e34a3398b7d02ad74","user":{"login":"mkangia","id":3864163,"avatar_url":"https://avatars3.githubusercontent.com/u/3864163?v=4","gravatar_id":"","url":"https://api.github.com/users/mkangia","html_url":"https://github.com/mkangia","followers_url":"https://api.github.com/users/mkangia/followers","following_url":"https://api.github.com/users/mkangia/following{/other_user}","gists_url":"https://api.github.com/users/mkangia/gists{/gist_id}","starred_url":"https://api.github.com/users/mkangia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkangia/subscriptions","organizations_url":"https://api.github.com/users/mkangia/orgs","repos_url":"https://api.github.com/users/mkangia/repos","events_url":"https://api.github.com/users/mkangia/events{/privacy}","received_events_url":"https://api.github.com/users/mkangia/received_events","type":"User","site_admin":false},"body":"this got removed in a later commit.","created_at":"2018-03-16T21:12:50Z","updated_at":"2018-03-16T21:12:50Z","html_url":"https://github.com/dimagi/commcare-cloud/pull/1475#discussion_r175215688","pull_request_url":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/1475","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/comments/175215688"},"html":{"href":"https://github.com/dimagi/commcare-cloud/pull/1475#discussion_r175215688"},"pull_request":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/1475"}},"in_reply_to_id":174760437},"pull_request":{"url":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/1475","id":174960438,"html_url":"https://github.com/dimagi/commcare-cloud/pull/1475","diff_url":"https://github.com/dimagi/commcare-cloud/pull/1475.diff","patch_url":"https://github.com/dimagi/commcare-cloud/pull/1475.patch","issue_url":"https://api.github.com/repos/dimagi/commcare-cloud/issues/1475","number":1475,"state":"open","locked":false,"title":"Add service management for pending services","user":{"login":"mkangia","id":3864163,"avatar_url":"https://avatars3.githubusercontent.com/u/3864163?v=4","gravatar_id":"","url":"https://api.github.com/users/mkangia","html_url":"https://github.com/mkangia","followers_url":"https://api.github.com/users/mkangia/followers","following_url":"https://api.github.com/users/mkangia/following{/other_user}","gists_url":"https://api.github.com/users/mkangia/gists{/gist_id}","starred_url":"https://api.github.com/users/mkangia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mkangia/subscriptions","organizations_url":"https://api.github.com/users/mkangia/orgs","repos_url":"https://api.github.com/users/mkangia/repos","events_url":"https://api.github.com/users/mkangia/events{/privacy}","received_events_url":"https://api.github.com/users/mkangia/received_events","type":"User","site_admin":false},"body":"This adds service management for \r\n- [x] celery\r\n- [x] webworkers\r\n- [x] formplayer -> includes formplayer-spring\r\n\r\nFollow up on [earlier PR](https://github.com/dimagi/commcare-cloud/pull/1452)\r\n[Issue](https://github.com/dimagi/commcare-cloud/issues/1243)","created_at":"2018-03-14T13:48:41Z","updated_at":"2018-03-16T21:12:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ffdaeff3879b51bc7492c9525c22be612002f9e2","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":209118547,"url":"https://api.github.com/repos/dimagi/commcare-cloud/labels/Open%20for%20review:%20hold%20off%20on%20merge","name":"Open for review: hold off on merge","color":"5319e7","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/1475/commits","review_comments_url":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/1475/comments","review_comment_url":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dimagi/commcare-cloud/issues/1475/comments","statuses_url":"https://api.github.com/repos/dimagi/commcare-cloud/statuses/b6a3d6a0da50a9fce1e9518734177ded64f5f413","head":{"label":"dimagi:mk-add-manage-services-2","ref":"mk-add-manage-services-2","sha":"b6a3d6a0da50a9fce1e9518734177ded64f5f413","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":22074543,"name":"commcare-cloud","full_name":"dimagi/commcare-cloud","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-cloud","description":null,"fork":false,"url":"https://api.github.com/repos/dimagi/commcare-cloud","forks_url":"https://api.github.com/repos/dimagi/commcare-cloud/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-cloud/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-cloud/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-cloud/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-cloud/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-cloud/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-cloud/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-cloud/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-cloud/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-cloud/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-cloud/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-cloud/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-cloud/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-cloud/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-cloud/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-cloud/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-cloud/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-cloud/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-cloud/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-cloud/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-cloud/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-cloud/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-cloud/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-cloud/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-cloud/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-cloud/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-cloud/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-cloud/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-cloud/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-cloud/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-cloud/deployments","created_at":"2014-07-21T18:04:26Z","updated_at":"2018-03-16T08:48:07Z","pushed_at":"2018-03-16T21:12:34Z","git_url":"git://github.com/dimagi/commcare-cloud.git","ssh_url":"git@github.com:dimagi/commcare-cloud.git","clone_url":"https://github.com/dimagi/commcare-cloud.git","svn_url":"https://github.com/dimagi/commcare-cloud","homepage":null,"size":6682,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":9,"mirror_url":null,"archived":false,"open_issues_count":21,"license":null,"forks":9,"open_issues":21,"watchers":7,"default_branch":"master"}},"base":{"label":"dimagi:master","ref":"master","sha":"0689aae71433eb7233aeed9ccd22327e48bc8eca","user":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"repo":{"id":22074543,"name":"commcare-cloud","full_name":"dimagi/commcare-cloud","owner":{"login":"dimagi","id":94514,"avatar_url":"https://avatars1.githubusercontent.com/u/94514?v=4","gravatar_id":"","url":"https://api.github.com/users/dimagi","html_url":"https://github.com/dimagi","followers_url":"https://api.github.com/users/dimagi/followers","following_url":"https://api.github.com/users/dimagi/following{/other_user}","gists_url":"https://api.github.com/users/dimagi/gists{/gist_id}","starred_url":"https://api.github.com/users/dimagi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimagi/subscriptions","organizations_url":"https://api.github.com/users/dimagi/orgs","repos_url":"https://api.github.com/users/dimagi/repos","events_url":"https://api.github.com/users/dimagi/events{/privacy}","received_events_url":"https://api.github.com/users/dimagi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dimagi/commcare-cloud","description":null,"fork":false,"url":"https://api.github.com/repos/dimagi/commcare-cloud","forks_url":"https://api.github.com/repos/dimagi/commcare-cloud/forks","keys_url":"https://api.github.com/repos/dimagi/commcare-cloud/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimagi/commcare-cloud/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimagi/commcare-cloud/teams","hooks_url":"https://api.github.com/repos/dimagi/commcare-cloud/hooks","issue_events_url":"https://api.github.com/repos/dimagi/commcare-cloud/issues/events{/number}","events_url":"https://api.github.com/repos/dimagi/commcare-cloud/events","assignees_url":"https://api.github.com/repos/dimagi/commcare-cloud/assignees{/user}","branches_url":"https://api.github.com/repos/dimagi/commcare-cloud/branches{/branch}","tags_url":"https://api.github.com/repos/dimagi/commcare-cloud/tags","blobs_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimagi/commcare-cloud/statuses/{sha}","languages_url":"https://api.github.com/repos/dimagi/commcare-cloud/languages","stargazers_url":"https://api.github.com/repos/dimagi/commcare-cloud/stargazers","contributors_url":"https://api.github.com/repos/dimagi/commcare-cloud/contributors","subscribers_url":"https://api.github.com/repos/dimagi/commcare-cloud/subscribers","subscription_url":"https://api.github.com/repos/dimagi/commcare-cloud/subscription","commits_url":"https://api.github.com/repos/dimagi/commcare-cloud/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimagi/commcare-cloud/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimagi/commcare-cloud/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimagi/commcare-cloud/issues/comments{/number}","contents_url":"https://api.github.com/repos/dimagi/commcare-cloud/contents/{+path}","compare_url":"https://api.github.com/repos/dimagi/commcare-cloud/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimagi/commcare-cloud/merges","archive_url":"https://api.github.com/repos/dimagi/commcare-cloud/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimagi/commcare-cloud/downloads","issues_url":"https://api.github.com/repos/dimagi/commcare-cloud/issues{/number}","pulls_url":"https://api.github.com/repos/dimagi/commcare-cloud/pulls{/number}","milestones_url":"https://api.github.com/repos/dimagi/commcare-cloud/milestones{/number}","notifications_url":"https://api.github.com/repos/dimagi/commcare-cloud/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimagi/commcare-cloud/labels{/name}","releases_url":"https://api.github.com/repos/dimagi/commcare-cloud/releases{/id}","deployments_url":"https://api.github.com/repos/dimagi/commcare-cloud/deployments","created_at":"2014-07-21T18:04:26Z","updated_at":"2018-03-16T08:48:07Z","pushed_at":"2018-03-16T21:12:34Z","git_url":"git://github.com/dimagi/commcare-cloud.git","ssh_url":"git@github.com:dimagi/commcare-cloud.git","clone_url":"https://github.com/dimagi/commcare-cloud.git","svn_url":"https://github.com/dimagi/commcare-cloud","homepage":null,"size":6682,"stargazers_count":7,"watchers_count":7,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":9,"mirror_url":null,"archived":false,"open_issues_count":21,"license":null,"forks":9,"open_issues":21,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/1475"},"html":{"href":"https://github.com/dimagi/commcare-cloud/pull/1475"},"issue":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/issues/1475"},"comments":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/issues/1475/comments"},"review_comments":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/1475/comments"},"review_comment":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/pulls/1475/commits"},"statuses":{"href":"https://api.github.com/repos/dimagi/commcare-cloud/statuses/b6a3d6a0da50a9fce1e9518734177ded64f5f413"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mkangia"}}