Installation
composer require bordeux/cron-bundle
Add to config/bundles.php:
Bordeaux\CronBundle\BordeauxCronBundle::class => ['all' => true],
Basic Configuration
Edit app/config/config.yml:
bordeaux_cron:
jobs:
my_job:
command: "app/console my:command"
schedule: "*/5 * * * *"
First Use Case Run the cron manager manually to test:
php app/console bordeaux:cron:run
Verify logs in var/log/cron.log (ensure monolog is configured).
Symfony Console Commands
app/console my:command) and reference it in bordeaux_cron.yml:
jobs:
my_job:
command: "app/console my:command --option=value"
schedule: "@hourly"
Sonata Admin Integration
SonataAdminBundle to trigger cron jobs via UI:
// src/Bordeaux/CronBundle/Admin/CronJobAdmin.php
class CronJobAdmin extends AbstractAdmin {
protected function configureFormFields(FormMapper $formMapper) {
$formMapper->add('schedule', 'sonata_type_model_list', [
'by_reference' => false,
'btn_list' => ['run' => ['link' => 'run']],
]);
}
}
Dynamic Scheduling
# .env
CRON_SCHEDULE_MY_JOB="*/10 * * * *"
Load via config.yml:
bordeaux_cron:
jobs:
my_job:
command: "app/console my:command"
schedule: "%env(CRON_SCHEDULE_MY_JOB)%"
Logging and Monitoring
// src/Bordeaux/CronBundle/Logger/CronLogger.php
class CronLogger extends AbstractLogger {
public function logExecution($jobName, $status) {
// Custom logic (e.g., database log, Slack alert)
}
}
Deprecated Symfony Versions
spatie/scheduler (Laravel)symfony/process + crontab (Symfony).Sonata Admin Dependency
SonataAdminBundle. If not using Sonata, the UI features are unavailable.Cron Daemon Requirement
cron daemon is configured. For testing, use:
* * * * * php /path/to/console bordeaux:cron:run >> /dev/null 2>&1
Schedule Syntax
php app/console bordeaux:cron:validate "*/5 * * * *"
Log Configuration
Ensure monolog is set up in app/config/config.yml:
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/cron.log"
level: debug
Job Execution Order
bordeaux_cron:
jobs:
z_high_priority_job: { command: "...", schedule: "..." }
a_low_priority_job: { command: "...", schedule: "..." }
Environment-Specific Schedules
Override schedules per environment (e.g., config_test.yml):
bordeaux_cron:
jobs:
my_job:
schedule: "@daily" # Overrides config.yml
Custom Job Classes
Extend Bordeaux\CronBundle\Job\AbstractJob for reusable logic:
class MyCustomJob extends AbstractJob {
protected function execute() {
// Custom logic
return $this->success("Done!");
}
}
Register in config.yml:
bordeaux_cron:
jobs:
custom_job:
class: AppBundle\Job\MyCustomJob
schedule: "* * * * *"
Pre/Post Hooks
Implement Bordeaux\CronBundle\Event\CronEvent listeners:
// src/AppBundle/EventListener/CronListener.php
class CronListener {
public function onCronRun(CronEvent $event) {
if ($event->getJobName() === 'my_job') {
// Pre/post logic
}
}
}
Bind in services.yml:
services:
app.cron_listener:
class: AppBundle\EventListener\CronListener
tags:
- { name: kernel.event_listener, event: bordeaux.cron.run, method: onCronRun }
Database-Backed Schedules
Store schedules in a database table (e.g., cron_jobs) and fetch them dynamically:
// src/Bordeaux/CronBundle/Provider/DatabaseJobProvider.php
class DatabaseJobProvider implements JobProviderInterface {
public function getJobs() {
return $this->entityManager->getRepository(CronJob::class)->findAll();
}
}
Configure in config.yml:
bordeaux_cron:
job_provider: app.database_job_provider
How can I help you explore Laravel packages today?