{"action":"created","comment":{"url":"https://api.github.com/repos/akeneo/BatchBundle/pulls/comments/28519329","id":28519329,"diff_hunk":"@@ -0,0 +1,128 @@\n+<?php\n+\n+namespace Akeneo\\Bundle\\BatchBundle\\Launcher;\n+\n+use Akeneo\\Bundle\\BatchBundle\\Entity\\JobExecution;\n+use Akeneo\\Bundle\\BatchBundle\\Entity\\JobInstance;\n+use Akeneo\\Bundle\\BatchBundle\\Job\\JobRepositoryInterface;\n+use Symfony\\Component\\Process\\PhpExecutableFinder;\n+use Symfony\\Component\\Security\\Core\\User\\UserInterface;\n+\n+/**\n+ * @author    Marie Bochu <marie.bochu@akeneo.com>\n+ * @copyright 2015 Akeneo SAS (http://www.akeneo.com)\n+ * @license   http://opensource.org/licenses/MIT MIT\n+ */\n+class SimpleJobLauncher implements JobLauncherInterface\n+{\n+    /** @var JobRepositoryInterface */\n+    protected $jobRepository;\n+\n+    /** @var string */\n+    protected $rootDir;\n+\n+    /** @var string */\n+    protected $environment;\n+\n+    /** @var array */\n+    protected $config = [];\n+\n+    /**\n+     * Constructor\n+     *\n+     * @param JobRepositoryInterface   $jobRepository\n+     * @param string                   $rootDir\n+     * @param string                   $environment\n+     */\n+    public function __construct(JobRepositoryInterface $jobRepository, $rootDir, $environment)\n+    {\n+        $this->jobRepository     = $jobRepository;\n+        $this->rootDir           = $rootDir;\n+        $this->environment       = $environment;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function launch(JobInstance $jobInstance, UserInterface $user, $rawConfiguration = null)\n+    {\n+        $jobExecution = $this->create($jobInstance, $user);\n+        $executionId  = $jobExecution->getId();\n+        $pathFinder   = new PhpExecutableFinder();\n+\n+        if ($this->isConfigTrue('upload')) {\n+            $rawConfiguration.= ' ' . addslashes(json_encode($jobInstance->getJob()->getConfiguration()));\n+        }\n+\n+        $cmd = sprintf(\n+            '%s %s/console akeneo:batch:job --env=%s %s %s %s %s >> %s/logs/batch_execute.log 2>&1',\n+            $pathFinder->find(),\n+            $this->rootDir,\n+            $this->environment,\n+            $this->isConfigTrue('email') ? sprintf('--email=\"%s\"', $user->getEmail()) : '',\n+            $jobInstance->getCode(),\n+            $executionId,\n+            !empty($rawConfiguration) ? sprintf('--config=\"%s\"', $rawConfiguration) : '',\n+            $this->rootDir\n+        );\n+\n+        $this->launchInBackground($cmd);\n+\n+        return $jobExecution;\n+    }\n+\n+    /**\n+     * {@inheritdoc}\n+     */\n+    public function launchInBackground($cmd)\n+    {\n+        // Please note we do not use Symfony Process as it has some problem\n+        // when executed from HTTP request that stop fast (race condition that makes\n+        // the process cloning fail when the parent process, i.e. HTTP request, stops\n+        // at the same time)\n+        exec($cmd . ' &');\n+    }\n+\n+    /**\n+     * Set config\n+     *\n+     * @param array $config\n+     *\n+     * @return JobLauncher\n+     */\n+    public function setConfig(array $config = [])","path":"Launcher/SimpleJobLauncher.php","position":93,"original_position":93,"commit_id":"d85488be4f55a9ee78c605f1d0dadedb6e6f688d","original_commit_id":"d85488be4f55a9ee78c605f1d0dadedb6e6f688d","user":{"login":"jjanvier","id":3691804,"avatar_url":"https://avatars.githubusercontent.com/u/3691804?v=3","gravatar_id":"","url":"https://api.github.com/users/jjanvier","html_url":"https://github.com/jjanvier","followers_url":"https://api.github.com/users/jjanvier/followers","following_url":"https://api.github.com/users/jjanvier/following{/other_user}","gists_url":"https://api.github.com/users/jjanvier/gists{/gist_id}","starred_url":"https://api.github.com/users/jjanvier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jjanvier/subscriptions","organizations_url":"https://api.github.com/users/jjanvier/orgs","repos_url":"https://api.github.com/users/jjanvier/repos","events_url":"https://api.github.com/users/jjanvier/events{/privacy}","received_events_url":"https://api.github.com/users/jjanvier/received_events","type":"User","site_admin":false},"body":"no need of `= []` in a setter","created_at":"2015-04-16T15:22:52Z","updated_at":"2015-04-16T15:22:52Z","html_url":"https://github.com/akeneo/BatchBundle/pull/61#discussion_r28519329","pull_request_url":"https://api.github.com/repos/akeneo/BatchBundle/pulls/61","_links":{"self":{"href":"https://api.github.com/repos/akeneo/BatchBundle/pulls/comments/28519329"},"html":{"href":"https://github.com/akeneo/BatchBundle/pull/61#discussion_r28519329"},"pull_request":{"href":"https://api.github.com/repos/akeneo/BatchBundle/pulls/61"}}},"pull_request":{"url":"https://api.github.com/repos/akeneo/BatchBundle/pulls/61","id":33446650,"html_url":"https://github.com/akeneo/BatchBundle/pull/61","diff_url":"https://github.com/akeneo/BatchBundle/pull/61.diff","patch_url":"https://github.com/akeneo/BatchBundle/pull/61.patch","issue_url":"https://api.github.com/repos/akeneo/BatchBundle/issues/61","number":61,"state":"open","locked":false,"title":"PIM-3881: add a job launcher","user":{"login":"skeleton","id":1131230,"avatar_url":"https://avatars.githubusercontent.com/u/1131230?v=3","gravatar_id":"","url":"https://api.github.com/users/skeleton","html_url":"https://github.com/skeleton","followers_url":"https://api.github.com/users/skeleton/followers","following_url":"https://api.github.com/users/skeleton/following{/other_user}","gists_url":"https://api.github.com/users/skeleton/gists{/gist_id}","starred_url":"https://api.github.com/users/skeleton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skeleton/subscriptions","organizations_url":"https://api.github.com/users/skeleton/orgs","repos_url":"https://api.github.com/users/skeleton/repos","events_url":"https://api.github.com/users/skeleton/events{/privacy}","received_events_url":"https://api.github.com/users/skeleton/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-16T12:44:02Z","updated_at":"2015-04-16T15:22:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d2b22af27a0eef90741be1a22ef25676363238db","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akeneo/BatchBundle/pulls/61/commits","review_comments_url":"https://api.github.com/repos/akeneo/BatchBundle/pulls/61/comments","review_comment_url":"https://api.github.com/repos/akeneo/BatchBundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akeneo/BatchBundle/issues/61/comments","statuses_url":"https://api.github.com/repos/akeneo/BatchBundle/statuses/d85488be4f55a9ee78c605f1d0dadedb6e6f688d","head":{"label":"akeneo:PIM-3881","ref":"PIM-3881","sha":"d85488be4f55a9ee78c605f1d0dadedb6e6f688d","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.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":16764304,"name":"BatchBundle","full_name":"akeneo/BatchBundle","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.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/BatchBundle","description":"Batch architecture bundle inspired by Spring Batch","fork":false,"url":"https://api.github.com/repos/akeneo/BatchBundle","forks_url":"https://api.github.com/repos/akeneo/BatchBundle/forks","keys_url":"https://api.github.com/repos/akeneo/BatchBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/BatchBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/BatchBundle/teams","hooks_url":"https://api.github.com/repos/akeneo/BatchBundle/hooks","issue_events_url":"https://api.github.com/repos/akeneo/BatchBundle/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/BatchBundle/events","assignees_url":"https://api.github.com/repos/akeneo/BatchBundle/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/BatchBundle/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/BatchBundle/tags","blobs_url":"https://api.github.com/repos/akeneo/BatchBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/BatchBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/BatchBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/BatchBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/BatchBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/BatchBundle/languages","stargazers_url":"https://api.github.com/repos/akeneo/BatchBundle/stargazers","contributors_url":"https://api.github.com/repos/akeneo/BatchBundle/contributors","subscribers_url":"https://api.github.com/repos/akeneo/BatchBundle/subscribers","subscription_url":"https://api.github.com/repos/akeneo/BatchBundle/subscription","commits_url":"https://api.github.com/repos/akeneo/BatchBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/BatchBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/BatchBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/BatchBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/BatchBundle/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/BatchBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/BatchBundle/merges","archive_url":"https://api.github.com/repos/akeneo/BatchBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/BatchBundle/downloads","issues_url":"https://api.github.com/repos/akeneo/BatchBundle/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/BatchBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/BatchBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/BatchBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/BatchBundle/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/BatchBundle/releases{/id}","created_at":"2014-02-12T10:55:28Z","updated_at":"2015-04-16T14:41:10Z","pushed_at":"2015-04-16T15:14:28Z","git_url":"git://github.com/akeneo/BatchBundle.git","ssh_url":"git@github.com:akeneo/BatchBundle.git","clone_url":"https://github.com/akeneo/BatchBundle.git","svn_url":"https://github.com/akeneo/BatchBundle","homepage":null,"size":1221,"stargazers_count":20,"watchers_count":20,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":22,"forks":9,"open_issues":22,"watchers":20,"default_branch":"master"}},"base":{"label":"akeneo:master","ref":"master","sha":"bbb06ea8c0ca702b15ab5848147cbcdbe6024f32","user":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.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":16764304,"name":"BatchBundle","full_name":"akeneo/BatchBundle","owner":{"login":"akeneo","id":2510186,"avatar_url":"https://avatars.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/BatchBundle","description":"Batch architecture bundle inspired by Spring Batch","fork":false,"url":"https://api.github.com/repos/akeneo/BatchBundle","forks_url":"https://api.github.com/repos/akeneo/BatchBundle/forks","keys_url":"https://api.github.com/repos/akeneo/BatchBundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akeneo/BatchBundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akeneo/BatchBundle/teams","hooks_url":"https://api.github.com/repos/akeneo/BatchBundle/hooks","issue_events_url":"https://api.github.com/repos/akeneo/BatchBundle/issues/events{/number}","events_url":"https://api.github.com/repos/akeneo/BatchBundle/events","assignees_url":"https://api.github.com/repos/akeneo/BatchBundle/assignees{/user}","branches_url":"https://api.github.com/repos/akeneo/BatchBundle/branches{/branch}","tags_url":"https://api.github.com/repos/akeneo/BatchBundle/tags","blobs_url":"https://api.github.com/repos/akeneo/BatchBundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akeneo/BatchBundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akeneo/BatchBundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/akeneo/BatchBundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akeneo/BatchBundle/statuses/{sha}","languages_url":"https://api.github.com/repos/akeneo/BatchBundle/languages","stargazers_url":"https://api.github.com/repos/akeneo/BatchBundle/stargazers","contributors_url":"https://api.github.com/repos/akeneo/BatchBundle/contributors","subscribers_url":"https://api.github.com/repos/akeneo/BatchBundle/subscribers","subscription_url":"https://api.github.com/repos/akeneo/BatchBundle/subscription","commits_url":"https://api.github.com/repos/akeneo/BatchBundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/akeneo/BatchBundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/akeneo/BatchBundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/akeneo/BatchBundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/akeneo/BatchBundle/contents/{+path}","compare_url":"https://api.github.com/repos/akeneo/BatchBundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akeneo/BatchBundle/merges","archive_url":"https://api.github.com/repos/akeneo/BatchBundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akeneo/BatchBundle/downloads","issues_url":"https://api.github.com/repos/akeneo/BatchBundle/issues{/number}","pulls_url":"https://api.github.com/repos/akeneo/BatchBundle/pulls{/number}","milestones_url":"https://api.github.com/repos/akeneo/BatchBundle/milestones{/number}","notifications_url":"https://api.github.com/repos/akeneo/BatchBundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akeneo/BatchBundle/labels{/name}","releases_url":"https://api.github.com/repos/akeneo/BatchBundle/releases{/id}","created_at":"2014-02-12T10:55:28Z","updated_at":"2015-04-16T14:41:10Z","pushed_at":"2015-04-16T15:14:28Z","git_url":"git://github.com/akeneo/BatchBundle.git","ssh_url":"git@github.com:akeneo/BatchBundle.git","clone_url":"https://github.com/akeneo/BatchBundle.git","svn_url":"https://github.com/akeneo/BatchBundle","homepage":null,"size":1221,"stargazers_count":20,"watchers_count":20,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":22,"forks":9,"open_issues":22,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akeneo/BatchBundle/pulls/61"},"html":{"href":"https://github.com/akeneo/BatchBundle/pull/61"},"issue":{"href":"https://api.github.com/repos/akeneo/BatchBundle/issues/61"},"comments":{"href":"https://api.github.com/repos/akeneo/BatchBundle/issues/61/comments"},"review_comments":{"href":"https://api.github.com/repos/akeneo/BatchBundle/pulls/61/comments"},"review_comment":{"href":"https://api.github.com/repos/akeneo/BatchBundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akeneo/BatchBundle/pulls/61/commits"},"statuses":{"href":"https://api.github.com/repos/akeneo/BatchBundle/statuses/d85488be4f55a9ee78c605f1d0dadedb6e6f688d"}}}}