With this package you can replace the default crontable. Or the Laravel's scheduling feature. This package allows you to define your crons in a database table and manage these from command or from an Admin panel. And you can run it from supervisor.
- Laravel 5.6
If you have problems with other versions please submit an issue.
Use composer to install CronBundle packages:
composer require Tolacika/Laravel-Cron-Bundle
Once CronBundle
is installed, run the migrations
php artisan migrate
And in case of need you can pubish the config file with this command:
php artisan vendor:publish --provider="Tolacika\CronBundle\CronBundleServiceProvider"
* * * * * php /path-to-your-project/artisan cron-bundle:execute >> /dev/null
[program:cron_bundle]
command=php artisan cron:start --blocking
process_name=%(program_name)s_%(process_num)02d
numprocs=1
autostart=true
autorestart=true
startsecs=0
user=www-data
redirect_stderr=true
stderr_logfile = /var/log/supervisor/cron_bundle_err.log
stdout_logfile = /var/log/supervisor/cron_bundle_stdout.log
stdout_logfile_maxbytes=10MB
stdout_logfile_backups=10
If you have PCNTL
PHP extension you can start a daemon worker with this command:
php artisan cron-bundle:start
You have several interactive commands to use for creating, deleting, enabling and disabling crons:
cron-bundle:list
- to list all jobcron-bundle:create
- to create a jobcron-bundle:delete {jobId}
- to delete a jobcron-bundle:enable {jobId}
- to enable a jobcron-bundle:disable {jobId}
- to disable a job
Also you have a fancy dashboard to manage your jobs. And from here you can see the run results and change logs.
After package installed and migration is done, you can access the dashboard in example.com/CronBundle
By default the dashboard only available in local environment. To change this behaviour place this snippet to your AppServiceProvider
's boot()
method, of course replace the auth()->check()
:
use Tolacika\CronBundle\CronBundle;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// ...
CronBundle::auth(function ($request) {
// returns true or false
return auth()->check();
});
// ...
}
If you are using log type other than none
, its useful to set the current user for logging. You can do this with CronBundle::setUser()
method in your AppServiceProvider
's boot()
method, like this:
use Tolacika\CronBundle\CronBundle;
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
// ...
CronBundle::setUser(function ($request) {
// the return type must be an integer, or null
return auth()->user() ? auth()->user()->id : null;
});
// ...
}
After publishing the config file, you can see some options in config/cron-bundle.php
. Each config entry is documented here.
Important versions listed below. Refer to the Changelog for a full history of the project.
Bug reports, feature requests, and pull requests can be submitted by following our Contribution Guide.
This software is released under the MIT License.
© 2017 Laszlo Toth, All rights reserved.