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

Cron Bundle Laravel Package

bigfoot/cron-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the bundle via Composer (though note the last release is from 2014—verify compatibility with your Laravel version or Symfony stack):

    composer require c2is/bigfoot-cron-bundle
    

    Register the bundle in config/bundles.php (Symfony) or manually bootstrap it if using Laravel’s Symfony integration.

  2. Configuration Locate config/bigfoot_cron.php (or define your own config) and set:

    return [
        'jobs' => [
            'my_job' => [
                'command' => 'app:cron-job',
                'schedule' => '*/5 * * * *', // Every 5 minutes
                'user' => 'www-data',       // User to run as
                'env' => 'production',      // Environment
            ],
        ],
    ];
    
  3. First Use Case Define a Laravel Artisan command (e.g., app/Console/Commands/CronJob.php) and reference it in the config under command. Test locally with:

    php artisan my_job
    

Implementation Patterns

Workflow: Job Definition & Scheduling

  1. Command-Based Jobs

    • Create Artisan commands for reusable cron tasks (e.g., SendReportsCommand).
    • Reference them in config/bigfoot_cron.php with cron syntax:
      'jobs' => [
          'send_reports' => [
              'command' => 'reports:send',
              'schedule' => '0 3 * * *', // Daily at 3 AM
          ],
      ],
      
  2. Environment-Specific Config Use Laravel’s config caching or Symfony’s environment variables to override schedules per environment:

    'schedule' => env('CRON_SCHEDULE', '*/10 * * * *'), // Fallback to every 10 mins
    
  3. Logging & Output Redirect command output to a log file for debugging:

    'command' => 'app:cleanup >> /var/log/cron/cleanup.log 2>&1',
    

Integration Tips

  • Laravel-Specific: Use Laravel’s Artisan::call() in commands to leverage queues/jobs internally.
  • Symfony Compatibility: If using Laravel’s Symfony bridge, ensure the bundle’s event listeners (e.g., CronEvent) are properly wired.
  • Docker/Serverless: For containerized setups, mount logs and use cron via crontab -e with the bundle’s generated commands.

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony 2.x

    • The bundle targets Symfony 2.x (2014). For Laravel 5.8+, use spatie/scheduler or laravel-schedule instead.
    • Workaround: Fork the repo and update dependencies if critical features are needed.
  2. Cron Syntax Errors

    • Validate schedules with crontab.guru. Example:
      // ❌ Invalid: '0 0 * * *' (missing day-of-week)
      // ✅ Valid: '0 0 * * 0' (Sunday at midnight)
      
  3. Permission Issues

    • Ensure the user in config has execute permissions for the command:
      chmod +x artisan
      sudo -u www-data php artisan my_job
      
  4. No Built-in Queue Support

    • The bundle runs commands directly. For async tasks, wrap commands in Laravel queues or use dispatch() inside the command.

Debugging

  • Dry Runs: Test schedules locally with:
    php artisan schedule:run
    
  • Log Inspection: Check /var/log/cron.log or redirect output as shown above.
  • Bundle Events: Listen for CronEvent to log job executions:
    public function onCron(CronEvent $event) {
        Log::info("Job {$event->getJob()} executed at {$event->getTimestamp()}");
    }
    

Extension Points

  1. Custom Job Classes Extend the bundle’s Job class to add metadata or pre/post hooks:

    class CustomJob extends \Bigfoot\CronBundle\Job {
        public function preExecute() {
            Log::debug("Pre-execution for {$this->getCommand()}");
        }
    }
    
  2. Dynamic Scheduling Override schedules at runtime via config listeners or environment variables.

  3. Alternative Schedulers For modern Laravel, replace with:

    • spatie/scheduler: For Symfony/Laravel hybrid apps.
    • laravel-schedule: Native Laravel solution with queue support.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky