Skip to content

Commit

Permalink
Merge pull request #75 from Indatus/develop
Browse files Browse the repository at this point in the history
New Config Option: executable
  • Loading branch information
bkuhl committed Sep 22, 2014
2 parents 704a4a4 + b36a430 commit 42c3202
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
23 changes: 17 additions & 6 deletions src/Indatus/Dispatcher/Services/CommandService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Indatus\Dispatcher\OptionReader;
use Indatus\Dispatcher\Scheduling\ScheduledCommand;
use Indatus\Dispatcher\Scheduling\ScheduledCommandInterface;
use Config;

class CommandService
{
Expand Down Expand Up @@ -170,9 +171,22 @@ public function getRunCommand(
/** @var \Indatus\Dispatcher\Platform $platform */
$platform = App::make('Indatus\Dispatcher\Platform');

$commandPieces = array('php');
if ($platform->isHHVM()) {
$commandPieces = array('hhvm');
//load executable path
$executablePath = Config::get('dispatcher::executable');
if (!is_null($executablePath)) {
$commandPieces = array($executablePath);
} else {
$commandPieces = array();

if ($platform->isUnix()) {
$commandPieces[] = '/usr/bin/env';
}

if ($platform->isHHVM()) {
$commandPieces[] = 'hhvm';
} else {
$commandPieces[] = 'php';
}
}

$commandPieces[] = base_path().'/artisan';
Expand All @@ -190,9 +204,6 @@ public function getRunCommand(
$commandPieces[] = '> /dev/null'; //don't show output, errors can be viewed in the Laravel log
$commandPieces[] = '&'; //run in background

//for linux, use environment variable
array_unshift($commandPieces, '/usr/bin/env');

//run the command as a different user
if (is_string($scheduledCommand->user())) {
array_unshift($commandPieces, 'sudo -u '.$scheduledCommand->user());
Expand Down
9 changes: 8 additions & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@
* Scheduler and SchedulerService classes.
*
*/
'driver' => 'cron'
'driver' => 'cron',

/**
* Customize the path to your PHP executable. If null, Dispatcher
* detects whether you're running HHVM or standard PHP and builds the
* executable path accordingly.
*/
'executable' => null
);
22 changes: 22 additions & 0 deletions tests/Services/TestCommandService.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,28 @@ public function testGetRunCommandWindows()
)));
}

public function testGetRunCommandExecutable()
{
$executablePath = '/path/to/executable';
Config::shouldReceive('get')->with('dispatcher::executable')->andReturn($executablePath);
$this->app->instance('Indatus\Dispatcher\Platform', m::mock('Indatus\Dispatcher\Platform', function ($m) {
$m->shouldReceive('isUnix')->andReturn(true);
$m->shouldReceive('isWindows')->andReturn(false);
}));

$commandName = 'test:command';
$scheduledCommand = $this->mockCommand();
$scheduledCommand->shouldReceive('getName')->andReturn($commandName);
$scheduledCommand->shouldReceive('user')->andReturn(false);
$this->assertEquals($this->commandService->getRunCommand($scheduledCommand), implode(' ', array(
$executablePath,
base_path().'/artisan',
$commandName,
'> /dev/null',
'&'
)));
}

public function testGetRunCommandHHVM()
{
$this->app->instance('Indatus\Dispatcher\Platform', m::mock('Indatus\Dispatcher\Platform', function ($m) {
Expand Down

0 comments on commit 42c3202

Please sign in to comment.