Skip to content

Commit

Permalink
EZP-31958: Allow console command specific extra options (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
homarx authored Sep 29, 2020
1 parent 5e888ae commit fea9a52
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The tag takes the following arguments:
- `name`: `ezplatform.cron.job`
- `schedule`: _Takes any kind of [format supported by cron/cron](https://github.com/Cron/Cron#crontab-syntax), which mimics linux crontab format. E.g. `* * * * *`_
- `category`: _(Optional, by default: `default`) Lets you separate cronjobs that should be run under different logic then default, e.g. infrequent jobs (NOTE: Means end user will need to setup several entries in his crontab to run all categories!)_
- `options`: _(Optional, by default: `''`) Takes custom option/s in string format which are added to the command. (E.g. '--keep=0 --status=draft' for running the cleanup versions command)_


### Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function process(ContainerBuilder $container)
$reference,
$cronJob['schedule'],
$cronJob['category'],
$cronJob['options'] ?? '',
]);
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/bundle/Registry/CronJobsRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class CronJobsRegistry
*/
protected $siteaccess;

/**
* @var string
*/
protected $options;

public function __construct(string $environment, SiteAccess $siteaccess)
{
$finder = new PhpExecutableFinder();
Expand All @@ -45,12 +50,13 @@ public function __construct(string $environment, SiteAccess $siteaccess)
$this->siteaccess = $siteaccess;
}

public function addCronJob(Command $command, string $schedule = null, string $category = self::DEFAULT_CATEGORY): void
public function addCronJob(Command $command, string $schedule = null, string $category = self::DEFAULT_CATEGORY, string $options = ''): void
{
$command = sprintf('%s %s %s --siteaccess=%s --env=%s',
$command = sprintf('%s %s %s %s --siteaccess=%s --env=%s',
$this->executable,
$_SERVER['SCRIPT_NAME'],
$command->getName(),
$options,
$this->siteaccess->name,
$this->environment
);
Expand Down

0 comments on commit fea9a52

Please # to comment.