{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/18471","repository_url":"https://api.github.com/repos/symfony/symfony","labels_url":"https://api.github.com/repos/symfony/symfony/issues/18471/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/18471/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/18471/events","html_url":"https://github.com/symfony/symfony/pull/18471","id":146581109,"number":18471,"title":"[Console] Add 'auto lockable' behaviour","user":{"login":"geoffrey-brier","id":1224811,"avatar_url":"https://avatars.githubusercontent.com/u/1224811?v=3","gravatar_id":"","url":"https://api.github.com/users/geoffrey-brier","html_url":"https://github.com/geoffrey-brier","followers_url":"https://api.github.com/users/geoffrey-brier/followers","following_url":"https://api.github.com/users/geoffrey-brier/following{/other_user}","gists_url":"https://api.github.com/users/geoffrey-brier/gists{/gist_id}","starred_url":"https://api.github.com/users/geoffrey-brier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoffrey-brier/subscriptions","organizations_url":"https://api.github.com/users/geoffrey-brier/orgs","repos_url":"https://api.github.com/users/geoffrey-brier/repos","events_url":"https://api.github.com/users/geoffrey-brier/events{/privacy}","received_events_url":"https://api.github.com/users/geoffrey-brier/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/Console","name":"Console","color":"DDDDDD"},{"url":"https://api.github.com/repos/symfony/symfony/labels/Feature","name":"Feature","color":"02e10c"},{"url":"https://api.github.com/repos/symfony/symfony/labels/Status:%20Needs%20Review","name":"Status: Needs Review","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-07T10:57:29Z","updated_at":"2016-04-07T13:55:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/18471","html_url":"https://github.com/symfony/symfony/pull/18471","diff_url":"https://github.com/symfony/symfony/pull/18471.diff","patch_url":"https://github.com/symfony/symfony/pull/18471.patch"},"body":"| Q             | A\r\n| ------------- | ---\r\n| Branch?       | \"master\"\r\n| Bug fix?      | no\r\n| New feature?  | yes\r\n| BC breaks?    | no\r\n| Deprecations? | no\r\n| Tests pass?   | yes\r\n| Fixed tickets | none\r\n| License       | MIT\r\n| Doc PR        | none for the moment :)\r\n\r\nHi there,\r\n\r\nSince the 2.6 the `LockHandler` class was added to ease concurrency problems. There was a nice post about [using it in your commands](http://symfony.com/blog/new-in-symfony-2-6-lockhandler).\r\n\r\nFrom my humble experience, I find it a bit unpleasant/time consuming to always copy/paste the same code. So here is my proposal:\r\n\r\nBefore:\r\n\r\n```php\r\nclass UpdateContentsCommand extends Command\r\n{\r\n    protected function configure()\r\n    {\r\n        // ...\r\n    }\r\n\r\n    protected function execute(InputInterface $input, OutputInterface $output)\r\n    {\r\n        // create the lock\r\n        $lock = new LockHandler('update:contents');\r\n        if (!$lock->lock()) {\r\n            $output->writeln('The command is already running in another process.');\r\n\r\n            return 0;\r\n        }\r\n\r\n      // Your code\r\n\r\n        $lock->release();\r\n    }\r\n}\r\n```\r\n\r\nAfter:\r\n\r\n```php\r\nclass UpdateContentsCommand extends Command\r\n{\r\n    protected function configure()\r\n    {\r\n         $this\r\n              ->setName('foo:bar')\r\n              // ...\r\n              ->setAutoLock(true);\r\n    }\r\n\r\n    protected function execute(InputInterface $input, OutputInterface $output)\r\n    {\r\n        // Your code\r\n    }\r\n}\r\n```\r\n\r\nWhat do you think ?"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/206917198","html_url":"https://github.com/symfony/symfony/pull/18471#issuecomment-206917198","issue_url":"https://api.github.com/repos/symfony/symfony/issues/18471","id":206917198,"user":{"login":"geoffrey-brier","id":1224811,"avatar_url":"https://avatars.githubusercontent.com/u/1224811?v=3","gravatar_id":"","url":"https://api.github.com/users/geoffrey-brier","html_url":"https://github.com/geoffrey-brier","followers_url":"https://api.github.com/users/geoffrey-brier/followers","following_url":"https://api.github.com/users/geoffrey-brier/following{/other_user}","gists_url":"https://api.github.com/users/geoffrey-brier/gists{/gist_id}","starred_url":"https://api.github.com/users/geoffrey-brier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geoffrey-brier/subscriptions","organizations_url":"https://api.github.com/users/geoffrey-brier/orgs","repos_url":"https://api.github.com/users/geoffrey-brier/repos","events_url":"https://api.github.com/users/geoffrey-brier/events{/privacy}","received_events_url":"https://api.github.com/users/geoffrey-brier/received_events","type":"User","site_admin":false},"created_at":"2016-04-07T13:54:59Z","updated_at":"2016-04-07T13:54:59Z","body":"@javiereguiluz I do agree with you, I wasn't really satisfied with the naming ... what about \"safe lock\", \"thread safe\" ... ?"}}