Skip to content

Commit

Permalink
Add Symfony process back but update version
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbushnell committed Apr 10, 2024
1 parent 23707b4 commit 8c18792
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trendyminds/yii2-scheduling",
"version": "2.0.0",
"version": "2.1.0",
"license": "MIT",
"description": "Scheduling extension for Yii2 framework",
"keywords": [
Expand All @@ -17,8 +17,9 @@
"type": "yii2-extension",
"require": {
"php": "^8.1.0",
"yiisoft/yii2": "2.0.*",
"dragonmantank/cron-expression": "1.*"
"dragonmantank/cron-expression": "1.*",
"symfony/process": "^5.4 || ^6.0 || ^7",
"yiisoft/yii2": "2.0.*"
},
"require-dev": {
"phpunit/phpunit": "4.8.36"
Expand Down
16 changes: 15 additions & 1 deletion src/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Cron\CronExpression;
use GuzzleHttp\Client as HttpClient;
use Symfony\Component\Process\Process;
use yii\base\Application;
use yii\base\Component;
use yii\base\InvalidCallException;
Expand Down Expand Up @@ -116,7 +117,7 @@ public function run(Application $app)
{
$this->trigger(self::EVENT_BEFORE_RUN);
if (count($this->_afterCallbacks) > 0) {
echo "Running commands in foreground is not supported. Please use the command in the background.";
$this->runCommandInForeground($app);
} else {
$this->runCommandInBackground($app);
}
Expand All @@ -133,6 +134,19 @@ protected function mutexName()
return 'framework/schedule-' . sha1($this->_expression . $this->command);
}

/**
* Run the command in the foreground.
*
* @param Application $app
*/
protected function runCommandInForeground(Application $app)
{
(new Process(
trim($this->buildCommand(), '& '), dirname($app->request->getScriptFile()), null, null, null
))->run();
$this->callAfterCallbacks($app);
}

/**
* Build the comand string.
*
Expand Down

0 comments on commit 8c18792

Please sign in to comment.