PHP code example of xactsystems / command-scheduler
1. Go to this page and download the library: Download xactsystems/command-scheduler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
xactsystems / command-scheduler example snippets
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
use Cron\CronExpression;
...
public function myControllerAction(CommandScheduler $scheduler)
{
$scheduledCommand = new ScheduledCommand();
$scheduledCommand->setDescription('My daily command');
$scheduledCommand->setCommand( 'app:my-daily-command' );
$scheduledCommand->setCronExpression( CronExpression::factory('@daily') );
$scheduledCommand->setPriority(5); // Defaults to 1
$scheduler->add( $scheduledCommand );
}
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
...
public function myControllerAction(int $commandId, CommandScheduler $scheduler)
{
$scheduler->disable($commandId);
}
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
...
public function myControllerAction(int $commandId, CommandScheduler $scheduler)
{
$scheduler->runImmediately($commandId);
}
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
...
public function myControllerAction(int $commandId, CommandScheduler $scheduler)
{
$scheduler->delete($commandId);
}
use Xact\CommandScheduler\Scheduler\CommandScheduler;
use Xact\CommandScheduler\Entity\ScheduledCommand;
...
public function myControllerAction(CommandScheduler $scheduler)
{
$commands = $scheduler->getActive();
foreach ($commands as $command) {
...
}
}
use Xact\CommandScheduler\CommandSchedulerFactory;
class MyController extends AbstractController
{
private CommandSchedulerFactory $commandFactory;
public function __controller(CommandSchedulerFactory $commandFactory) {
$this->commandFactory = $commandFactory;
}
public function myEmailAction(EntityManagerInterface $em) {
$myLargeDataObject = 'Some enormous serialized value you want to store in the command and probably delete once the command is complete.';
$command = $this->commandFactory->createImmediateCommand(
'My test command',
'app:test-command',
null,
$myLargeDataObject,
);
$em->persist($command);
$em->flush();
}
}
/**
* Create a command to run immediately
*
* @param string[]|null $arguments
* @param bool|null $clearData If null, the configuration value 'clear_data' is used. Default true.
* @param bool|null $retryOnFail If null, the configuration value 'retry_on_fail' is used. Default false.
* @param int|null $retryDelay If null, the configuration value 'retry_delay' is used. Default 60.
* @param int|null $retryMaxAttempts If null, the configuration value 'retry_max_attempts' is used. Default 60.
*/
public function createImmediateCommand(
string $description,
string $command,
?array $arguments = null,
?string $data = null,
?bool $clearData = null,
?bool $retryOnFail = null,
?int $retryDelay = null,
?int $retryMaxAttempts = null
): ScheduledCommand {}
/**
* Create a command scheduled by a CRON expression
*
* @param string[]|null $arguments
* @param bool|null $clearData If null, the configuration value 'clear_data' is used. Default true.
* @param bool|null $retryOnFail If null, the configuration value 'retry_on_fail' is used. Default false.
* @param int|null $retryDelay If null, the configuration value 'retry_delay' is used. Default 60.
* @param int|null $retryMaxAttempts If null, the configuration value 'retry_max_attempts' is used. Default 60.
*/
public function createCronCommand(
string $cronExpression,
string $description,
string $command,
?array $arguments = null,
?string $data = null,
?bool $clearData = null,
?bool $retryOnFail = null,
?int $retryDelay = null,
?int $retryMaxAttempts = null
): ScheduledCommand {}
bash
php bin/console doctrine:schema:create
bash
php bin/console xact:command-scheduler
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.