carlossosa88/command-scheduler-bundle
Installation
composer require carlossosa88/command-scheduler-bundle
Register the bundle in config/bundles.php (Symfony):
CarlosSosa\CommandSchedulerBundle\CarlosSosaCommandSchedulerBundle::class => ['all' => true],
Configuration Publish the default config:
php bin/console carlos-sosa:command-scheduler:install
Edit config/packages/carlos_sosa_command_scheduler.yaml to define schedules (e.g., cron syntax):
carlos_sosa_command_scheduler:
commands:
app:send-emails:
schedule: "0 12 * * *" # Daily at noon
timezone: "Europe/Paris"
First Use Case
Schedule a Laravel Artisan command (e.g., queue:work):
carlos_sosa_command_scheduler:
commands:
artisan:queue:work:
schedule: "*/5 * * * *" # Every 5 minutes
Verify with:
php bin/console carlos-sosa:command-scheduler:list
Defining Schedules
config/packages/...) for maintainability.artisan:log:rotate:
schedule: "0 * * * *"
Dynamic Scheduling
EventSubscriber:
use CarlosSosa\CommandSchedulerBundle\Event\ScheduleEvent;
public function onSchedule(ScheduleEvent $event) {
$event->setSchedule('*/10 * * * *'); // Update runtime
}
Environment-Specific Configs
%env% or Laravel’s .env for environment variables:
schedule: "%app.cron.schedule%" # e.g., "0 3 * * *" in .env
Integration with Laravel
artisan: prefix:
artisan:app:backup:run # Maps to `php artisan app:backup:run`
Logging & Monitoring
var/log/command_scheduler.log (configurable).bin/console debug:router or custom endpoints.Timezone Mismatches
timezone: "America/New_York"
php bin/console debug:config carlos_sosa_command_scheduler
Command Output Handling
options:
- "--log-file=/var/log/mycommand.log"
Circular Dependencies
A → B → A).Permission Issues
www-data) has execute permissions for commands:
chmod +x bin/console
dry_run: true
php bin/console carlos-sosa:command-scheduler:run app:send-emails
var/log/command_scheduler.log for errors. Increase verbosity:
logging:
level: debug
Custom Command Handlers
Extend CarlosSosa\CommandSchedulerBundle\Command\AbstractCommand for non-Artisan commands.
Pre/Post Hooks
Use Symfony events (kernel.request, console.command) to intercept commands.
Database Backend Fork the bundle to replace the config-based scheduler with a Doctrine entity (e.g., for dynamic schedules).
Laravel-Specific Tweaks
ConsoleApplication to integrate with Laravel’s service provider:
// In CarlosSosaCommandSchedulerBundle.php
public function boot() {
$this->container->get('kernel')->getContainerBuilder()
->registerExtension(new LaravelServiceExtension());
}
How can I help you explore Laravel packages today?