Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Command Scheduler Bundle Laravel Package

carlossosa88/command-scheduler-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require carlossosa88/command-scheduler-bundle
    

    Register the bundle in config/bundles.php (Symfony):

    CarlosSosa\CommandSchedulerBundle\CarlosSosaCommandSchedulerBundle::class => ['all' => true],
    
  2. 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"
    
  3. 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
    

Implementation Patterns

Workflows

  1. Defining Schedules

    • Use YAML/XML/JSON config (via config/packages/...) for maintainability.
    • Example: Rotate logs hourly:
      artisan:log:rotate:
          schedule: "0 * * * *"
      
  2. Dynamic Scheduling

    • Override schedules programmatically via EventSubscriber:
      use CarlosSosa\CommandSchedulerBundle\Event\ScheduleEvent;
      
      public function onSchedule(ScheduleEvent $event) {
          $event->setSchedule('*/10 * * * *'); // Update runtime
      }
      
  3. Environment-Specific Configs

    • Use Symfony’s %env% or Laravel’s .env for environment variables:
      schedule: "%app.cron.schedule%"  # e.g., "0 3 * * *" in .env
      
  4. Integration with Laravel

    • Proxy Laravel commands via Symfony’s artisan: prefix:
      artisan:app:backup:run  # Maps to `php artisan app:backup:run`
      
  5. Logging & Monitoring

    • Log command execution to var/log/command_scheduler.log (configurable).
    • Add health checks via Symfony’s bin/console debug:router or custom endpoints.

Gotchas and Tips

Pitfalls

  1. Timezone Mismatches

    • Defaults to server timezone. Explicitly set in config:
      timezone: "America/New_York"
      
    • Debug with:
      php bin/console debug:config carlos_sosa_command_scheduler
      
  2. Command Output Handling

    • Commands run in detached processes. Redirect output to files or logs:
      options:
          - "--log-file=/var/log/mycommand.log"
      
  3. Circular Dependencies

    • Avoid scheduling commands that trigger other scheduled commands (e.g., ABA).
  4. Permission Issues

    • Ensure the web server user (e.g., www-data) has execute permissions for commands:
      chmod +x bin/console
      

Debugging

  • Dry Run Mode Enable in config to test schedules without execution:
    dry_run: true
    
  • Manual Trigger Force-run a command:
    php bin/console carlos-sosa:command-scheduler:run app:send-emails
    
  • Logs Check var/log/command_scheduler.log for errors. Increase verbosity:
    logging:
        level: debug
    

Extension Points

  1. Custom Command Handlers Extend CarlosSosa\CommandSchedulerBundle\Command\AbstractCommand for non-Artisan commands.

  2. Pre/Post Hooks Use Symfony events (kernel.request, console.command) to intercept commands.

  3. Database Backend Fork the bundle to replace the config-based scheduler with a Doctrine entity (e.g., for dynamic schedules).

  4. Laravel-Specific Tweaks

    • Override the Symfony ConsoleApplication to integrate with Laravel’s service provider:
      // In CarlosSosaCommandSchedulerBundle.php
      public function boot() {
          $this->container->get('kernel')->getContainerBuilder()
              ->registerExtension(new LaravelServiceExtension());
      }
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle