{"action":"created","comment":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/119065251","pull_request_review_id":40910477,"id":119065251,"diff_hunk":"@@ -0,0 +1,121 @@\n+<?php\n+\n+\n+namespace Akeneo\\Bundle\\BatchBundle\\EventListener;\n+\n+\n+use Symfony\\Component\\Console\\ConsoleEvents;\n+use Symfony\\Component\\Console\\Event\\ConsoleCommandEvent;\n+use Symfony\\Component\\Console\\Event\\ConsoleEvent;\n+use Symfony\\Component\\EventDispatcher\\EventSubscriberInterface;\n+use Symfony\\Component\\Filesystem\\LockHandler;\n+\n+/**\n+ * Subscriber to lock and unlock commands\n+ *\n+ * @Author Benoit Wannepain <benoit.wannepain@gmail.com>\n+ * @copyright 2017 Akeneo SAS (http://www.akeneo.com)\n+ * @license   http://opensource.org/licenses/MIT MIT\n+ */\n+class LockSubscriber implements EventSubscriberInterface\n+{\n+    /** @var array */\n+    protected $managedJobCodes;\n+\n+    /** @var LockHandler */\n+    protected $lockHandler;\n+\n+    /** @var string */\n+    protected $currentJobCode;\n+\n+    /**\n+     * LockSubscriber constructor.\n+     */\n+    public function __construct()\n+    {\n+        $this->managedJobCodes = [];\n+    }\n+\n+    /**\n+     * @param string $jobCode\n+     */\n+    public function registerJobCode($jobCode)\n+    {\n+        $this->managedJobCodes[] = $jobCode;\n+    }\n+\n+    /**\n+     * Returns an array of event names this subscriber wants to listen to.\n+     *\n+     * @return array The event names to listen to\n+     *\n+     * @api\n+     */\n+    public static function getSubscribedEvents()\n+    {\n+        return [\n+            ConsoleEvents::COMMAND => 'onCommandStart',\n+            ConsoleEvents::TERMINATE => 'onCommandTerminate',\n+            ConsoleEvents::EXCEPTION => 'onCommandTerminate',\n+        ];\n+    }\n+\n+    /**\n+     * @param ConsoleCommandEvent $event\n+     */\n+    public function onCommandStart(ConsoleCommandEvent $event)\n+    {\n+        if (false === $this->supportsCommand($event)) {\n+\n+            return;\n+        }\n+\n+        $output = $event->getOutput();\n+        $this->lockHandler = new LockHandler($this->currentJobCode);\n+        if (!$this->lockHandler->lock()) {\n+            $output->writeln(sprintf('<error>Command already locked by %s</error>', get_class($this)));\n+            $event->disableCommand();\n+        } else {\n+            $output->writeln(sprintf('<info>Command locked by %s</info>', get_class($this)));\n+        }\n+    }\n+\n+    /**\n+     * @param ConsoleEvent $event\n+     */\n+    public function onCommandTerminate(ConsoleEvent $event)\n+    {\n+        if ($event->getExitCode() === ConsoleCommandEvent::RETURN_CODE_DISABLED\n+            || false === $this->supportsCommand($event)) {\n+","path":"src/Akeneo/Bundle/BatchBundle/EventListener/LockSubscriber.php","position":null,"original_position":90,"commit_id":"e522d1a1d54544408b3618dcf2318bb9d5201c07","original_commit_id":"e82a52c5f0c71d2d47316fa4404999bc2192f738","user":{"login":"bOnepain","id":524298,"avatar_url":"https://avatars0.githubusercontent.com/u/524298?v=3","gravatar_id":"","url":"https://api.github.com/users/bOnepain","html_url":"https://github.com/bOnepain","followers_url":"https://api.github.com/users/bOnepain/followers","following_url":"https://api.github.com/users/bOnepain/following{/other_user}","gists_url":"https://api.github.com/users/bOnepain/gists{/gist_id}","starred_url":"https://api.github.com/users/bOnepain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bOnepain/subscriptions","organizations_url":"https://api.github.com/users/bOnepain/orgs","repos_url":"https://api.github.com/users/bOnepain/repos","events_url":"https://api.github.com/users/bOnepain/events{/privacy}","received_events_url":"https://api.github.com/users/bOnepain/received_events","type":"User","site_admin":false},"body":"done","created_at":"2017-05-30T10:38:43Z","updated_at":"2017-05-30T10:38:44Z","html_url":"https://github.com/akeneo/pim-community-dev/pull/6043#discussion_r119065251","pull_request_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/6043","_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments/119065251"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/6043#discussion_r119065251"},"pull_request":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/6043"}}},"pull_request":{"url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/6043","id":114798087,"html_url":"https://github.com/akeneo/pim-community-dev/pull/6043","diff_url":"https://github.com/akeneo/pim-community-dev/pull/6043.diff","patch_url":"https://github.com/akeneo/pim-community-dev/pull/6043.patch","issue_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/6043","number":6043,"state":"open","locked":false,"title":"[Contribution] Add subscriber to lock/unlock batch job commands","user":{"login":"bOnepain","id":524298,"avatar_url":"https://avatars0.githubusercontent.com/u/524298?v=3","gravatar_id":"","url":"https://api.github.com/users/bOnepain","html_url":"https://github.com/bOnepain","followers_url":"https://api.github.com/users/bOnepain/followers","following_url":"https://api.github.com/users/bOnepain/following{/other_user}","gists_url":"https://api.github.com/users/bOnepain/gists{/gist_id}","starred_url":"https://api.github.com/users/bOnepain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bOnepain/subscriptions","organizations_url":"https://api.github.com/users/bOnepain/orgs","repos_url":"https://api.github.com/users/bOnepain/repos","events_url":"https://api.github.com/users/bOnepain/events{/privacy}","received_events_url":"https://api.github.com/users/bOnepain/received_events","type":"User","site_admin":false},"body":"[//]: <> (<3 Thanks for taking the time to contribute! You're awesome! <3)\r\n\r\n[//]: <> (If you've never contributed to this repository before, please read https://github.com/akeneo/pim-community-dev/blob/master/.github/CONTRIBUTING.md)\r\n\r\n**Description (for Contributor and Core Developer)**\r\nAdd the possibility to lock a batch job to avoid concurrency:\r\n\r\n- Add a 'lock' attribute to the 'akeneo_batch.job' tag. It's not mandatory and false by default. Its value is boolean true or false. Batch job services tagged with the 'lock' attribute will be registered in a compiler pass to the LockSubscriber, that will handle locking and unlocking\r\n- Add a 'no-lock' option the BatchCommand, to skip locking even if the job is configured to be locked.\r\n\r\n\r\n[//]: <> (What does this Pull Request do? reference the related issue?)\r\n\r\n**Definition Of Done (for Core Developer only)**\r\n\r\n| Q                                 | A\r\n| --------------------------------- | ---\r\n| Added Specs                       | no\r\n| Added Behats                      | no\r\n| Added integration tests           | no\r\n| Changelog updated                 | no\r\n| Review and 2 GTM                  | no\r\n| Micro Demo to the PO (Story only) | no\r\n| Migration script                  | -\r\n| Tech Doc                          | -\r\n\r\n`Todo`: Pending / Work in progress\r\n`OK`: Done / Validated\r\n`-`: Not needed\r\n","created_at":"2017-04-07T11:37:54Z","updated_at":"2017-05-30T10:38:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"edaa1d828a7ac924c157fc4fbc1ad8d62f72b01f","assignee":{"login":"SamirBoulil","id":1826473,"avatar_url":"https://avatars2.githubusercontent.com/u/1826473?v=3","gravatar_id":"","url":"https://api.github.com/users/SamirBoulil","html_url":"https://github.com/SamirBoulil","followers_url":"https://api.github.com/users/SamirBoulil/followers","following_url":"https://api.github.com/users/SamirBoulil/following{/other_user}","gists_url":"https://api.github.com/users/SamirBoulil/gists{/gist_id}","starred_url":"https://api.github.com/users/SamirBoulil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamirBoulil/subscriptions","organizations_url":"https://api.github.com/users/SamirBoulil/orgs","repos_url":"https://api.github.com/users/SamirBoulil/repos","events_url":"https://api.github.com/users/SamirBoulil/events{/privacy}","received_events_url":"https://api.github.com/users/SamirBoulil/received_events","type":"User","site_admin":false},"assignees":[{"login":"SamirBoulil","id":1826473,"avatar_url":"https://avatars2.githubusercontent.com/u/1826473?v=3","gravatar_id":"","url":"https://api.github.com/users/SamirBoulil","html_url":"https://github.com/SamirBoulil","followers_url":"https://api.github.com/users/SamirBoulil/followers","following_url":"https://api.github.com/users/SamirBoulil/following{/other_user}","gists_url":"https://api.github.com/users/SamirBoulil/gists{/gist_id}","starred_url":"https://api.github.com/users/SamirBoulil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SamirBoulil/subscriptions","organizations_url":"https://api.github.com/users/SamirBoulil/orgs","repos_url":"https://api.github.com/users/SamirBoulil/repos","events_url":"https://api.github.com/users/SamirBoulil/events{/privacy}","received_events_url":"https://api.github.com/users/SamirBoulil/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/6043/commits","review_comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/6043/comments","review_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/6043/comments","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/e522d1a1d54544408b3618dcf2318bb9d5201c07","head":{"label":"bOnepain:feature/LockSubscriber","ref":"feature/LockSubscriber","sha":"e522d1a1d54544408b3618dcf2318bb9d5201c07","user":{"login":"bOnepain","id":524298,"avatar_url":"https://avatars0.githubusercontent.com/u/524298?v=3","gravatar_id":"","url":"https://api.github.com/users/bOnepain","html_url":"https://github.com/bOnepain","followers_url":"https://api.github.com/users/bOnepain/followers","following_url":"https://api.github.com/users/bOnepain/following{/other_user}","gists_url":"https://api.github.com/users/bOnepain/gists{/gist_id}","starred_url":"https://api.github.com/users/bOnepain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bOnepain/subscriptions","organizations_url":"https://api.github.com/users/bOnepain/orgs","repos_url":"https://api.github.com/users/bOnepain/repos","events_url":"https://api.github.com/users/bOnepain/events{/privacy}","received_events_url":"https://api.github.com/users/bOnepain/received_events","type":"User","site_admin":false},"repo":{"id":87537135,"name":"pim-community-dev","full_name":"bOnepain/pim-community-dev","owner":{"login":"bOnepain","id":524298,"avatar_url":"https://avatars0.githubusercontent.com/u/524298?v=3","gravatar_id":"","url":"https://api.github.com/users/bOnepain","html_url":"https://github.com/bOnepain","followers_url":"https://api.github.com/users/bOnepain/followers","following_url":"https://api.github.com/users/bOnepain/following{/other_user}","gists_url":"https://api.github.com/users/bOnepain/gists{/gist_id}","starred_url":"https://api.github.com/users/bOnepain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bOnepain/subscriptions","organizations_url":"https://api.github.com/users/bOnepain/orgs","repos_url":"https://api.github.com/users/bOnepain/repos","events_url":"https://api.github.com/users/bOnepain/events{/privacy}","received_events_url":"https://api.github.com/users/bOnepain/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bOnepain/pim-community-dev","description":"[Community Development Repository] The open source Product Information Management (PIM)","fork":true,"url":"https://api.github.com/repos/bOnepain/pim-community-dev","forks_url":"https://api.github.com/repos/bOnepain/pim-community-dev/forks","keys_url":"https://api.github.com/repos/bOnepain/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bOnepain/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bOnepain/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/bOnepain/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/bOnepain/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/bOnepain/pim-community-dev/events","assignees_url":"https://api.github.com/repos/bOnepain/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/bOnepain/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/bOnepain/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/bOnepain/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bOnepain/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bOnepain/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/bOnepain/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bOnepain/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/bOnepain/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/bOnepain/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/bOnepain/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/bOnepain/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/bOnepain/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/bOnepain/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/bOnepain/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/bOnepain/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/bOnepain/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/bOnepain/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/bOnepain/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bOnepain/pim-community-dev/merges","archive_url":"https://api.github.com/repos/bOnepain/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bOnepain/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/bOnepain/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/bOnepain/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/bOnepain/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/bOnepain/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bOnepain/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/bOnepain/pim-community-dev/releases{/id}","deployments_url":"https://api.github.com/repos/bOnepain/pim-community-dev/deployments","created_at":"2017-04-07T11:03:03Z","updated_at":"2017-04-07T11:03:17Z","pushed_at":"2017-05-30T10:32:58Z","git_url":"git://github.com/bOnepain/pim-community-dev.git","ssh_url":"git@github.com:bOnepain/pim-community-dev.git","clone_url":"https://github.com/bOnepain/pim-community-dev.git","svn_url":"https://github.com/bOnepain/pim-community-dev","homepage":"http://www.akeneo.com","size":100826,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"akeneo:master","ref":"master","sha":"8903268f79ffde9f0062c4e0da03942ec3386521","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars3.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"repo":{"id":5367323,"name":"pim-community-dev","full_name":"akeneo/pim-community-dev","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars3.githubusercontent.com/u/2510186?v=3","gravatar_id":"","url":"https://api.github.com/users/akeneo","html_url":"https://github.com/akeneo","followers_url":"https://api.github.com/users/akeneo/followers","following_url":"https://api.github.com/users/akeneo/following{/other_user}","gists_url":"https://api.github.com/users/akeneo/gists{/gist_id}","starred_url":"https://api.github.com/users/akeneo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akeneo/subscriptions","organizations_url":"https://api.github.com/users/akeneo/orgs","repos_url":"https://api.github.com/users/akeneo/repos","events_url":"https://api.github.com/users/akeneo/events{/privacy}","received_events_url":"https://api.github.com/users/akeneo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akeneo/pim-community-dev","description":"[Community Development Repository] The open source Product Information Management (PIM)","fork":false,"url":"https://api.github.com/repos/akeneo/pim-community-dev","forks_url":"https://api.github.com/repos/akeneo/pim-community-dev/forks","keys_url":"https://api.github.com/repos/akeneo/pim-community-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/pim-community-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/pim-community-dev/teams","hooks_url":"https://api.github.com/repos/akeneo/pim-community-dev/hooks","issue_events_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/pim-community-dev/events","assignees_url":"https://api.github.com/repos/akeneo/pim-community-dev/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/pim-community-dev/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/tags","blobs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/pim-community-dev/languages","stargazers_url":"https://api.github.com/repos/akeneo/pim-community-dev/stargazers","contributors_url":"https://api.github.com/repos/akeneo/pim-community-dev/contributors","subscribers_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscribers","subscription_url":"https://api.github.com/repos/akeneo/pim-community-dev/subscription","commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/pim-community-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/pim-community-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/pim-community-dev/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/pim-community-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/pim-community-dev/merges","archive_url":"https://api.github.com/repos/akeneo/pim-community-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/pim-community-dev/downloads","issues_url":"https://api.github.com/repos/akeneo/pim-community-dev/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/pim-community-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/pim-community-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/pim-community-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/pim-community-dev/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/pim-community-dev/releases{/id}","deployments_url":"https://api.github.com/repos/akeneo/pim-community-dev/deployments","created_at":"2012-08-10T09:27:26Z","updated_at":"2017-05-30T08:03:05Z","pushed_at":"2017-05-30T10:33:00Z","git_url":"git://github.com/akeneo/pim-community-dev.git","ssh_url":"git@github.com:akeneo/pim-community-dev.git","clone_url":"https://github.com/akeneo/pim-community-dev.git","svn_url":"https://github.com/akeneo/pim-community-dev","homepage":"http://www.akeneo.com","size":108837,"stargazers_count":410,"watchers_count":410,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":233,"mirror_url":null,"open_issues_count":121,"forks":233,"open_issues":121,"watchers":410,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/6043"},"html":{"href":"https://github.com/akeneo/pim-community-dev/pull/6043"},"issue":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/6043"},"comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/issues/6043/comments"},"review_comments":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/6043/comments"},"review_comment":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/pulls/6043/commits"},"statuses":{"href":"https://api.github.com/repos/akeneo/pim-community-dev/statuses/e522d1a1d54544408b3618dcf2318bb9d5201c07"}}}}
{"actor":{"display_login":"bOnepain"}}