nisanov / cron-command-bundle
A Symfony bundle that manages and integrates commands with the Linux crontab, by tracking command execution status and identifying commands that are overdue.
Requires
- php: >=7.1.5
- doctrine/doctrine-bundle: ^1.3
- doctrine/orm: ^2.4
- mtdowling/cron-expression: ^1.2
- symfony/framework-bundle: ^3.0
Requires (Dev)
- phpunit/phpunit: ^6.0
- symfony/symfony: ^3.0
README
A Symfony bundle that manages and integrates commands with the Linux crontab, by tracking command execution status and identifying commands that are overdue.
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download th e latest stable version of this bundle:
$ composer require nisanov/cron-command-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Step 2: Enable the Bundle
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Nisanov\CronCommandBundle\NisanovCronCommandBundle(),
];
// ...
}
// ...
}
Step 3: Update the database
php bin/console doctrine:schema:update --force
Usage
Adding/Modifying a command to the database and crontab
php bin/console cron:command:set
Follow the prompts after executing the above command to add or modify a command to the database and the crontab.
Removing a command from the database and crontab
php bin/console cron:command:set --remove
Follow the prompts after executing the above command to remove a command from the database and the crontab.
Synchronizing commands with the crontab after any manual manipulation of either.
php bin/console cron:command:synchronize
Getting statistical information on active commands stored in the database and crontab
php bin/console cron:command:statistics
Statistical information is displayed in the console after executing the above command.
The following service request provides the same information that can be utilized by other aspects of your application.
// reference the container in a context applicable way
$container->get('nisanov_cron_command.manager')->statistics();
Example
======================== =========== ===================== ===================== ===================== ============ =========== ==============
Name Schedule Created At Last Success Ran At Next Run At Is Overdue Exit Code Exit Message
======================== =========== ===================== ===================== ===================== ============ =========== ==============
swiftmailer:spool:send * * * * * 2017-05-15 10:15:30 2017-05-15 10:16:02 2017-05-15 10:17:00 0 0
======================== =========== ===================== ===================== ===================== ============ =========== ==============
Testing
Run phpunit tests with the following command:
vendor/bin/phpunit -c vendor/nisanov/cron-command-bundle/phpunit.xml.dist
WARNING: The unit tests manipulate the real crontab.