Skip to content

Commit

Permalink
Merge pull request #46 from bosix/enable-error-output
Browse files Browse the repository at this point in the history
add option to enable/avoid error output
  • Loading branch information
omnilight authored Jul 9, 2019
2 parents b1a9292 + d57ec88 commit f69a770
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ class Event extends Component
*/
protected $_mutex;

/**
* Decide if errors will be displayed.
*
* @var bool
*/
protected $_omitErrors = false;

/**
* Create a new event instance.
*
Expand Down Expand Up @@ -147,7 +154,7 @@ protected function runCommandInForeground(Application $app)
*/
public function buildCommand()
{
$command = $this->command . $this->_redirect . $this->_output . ' 2>&1 &';
$command = $this->command . $this->_redirect . $this->_output . ' ' . (($this->_omitErrors) ? ' 2>&1 &' : '');
return $this->_user ? 'sudo -u ' . $this->_user . ' ' . $command : $command;
}

Expand Down Expand Up @@ -505,6 +512,18 @@ public function user($user)
return $this;
}

/**
* Set if errors should be displayed
*
* @param bool $omitErrors
* @return $this
*/
public function omitErrors(bool $omitErrors = false)
{
$this->_omitErrors = $omitErrors;
return $this;
}

/**
* Do not allow the event to overlap each other.
*
Expand Down
8 changes: 7 additions & 1 deletion src/ScheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ class ScheduleController extends Controller
*/
public $scheduleFile;

/**
* @var bool set to true to avoid error output
*/
public $omitErrors = false;

public function options($actionID)
{
return array_merge(parent::options($actionID),
$actionID == 'run' ? ['scheduleFile'] : []
$actionID == 'run' ? ['scheduleFile', 'omitErrors'] : []
);
}

Expand All @@ -45,6 +50,7 @@ public function actionRun()
$events = $this->schedule->dueEvents(\Yii::$app);

foreach ($events as $event) {
$event->omitErrors($this->omitErrors);
$this->stdout('Running scheduled command: '.$event->getSummaryForDisplay()."\n");
$event->run(\Yii::$app);
}
Expand Down

0 comments on commit f69a770

Please sign in to comment.