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

Php Resque Scheduler Laravel Package

david-garcia/php-resque-scheduler

PHP port of resque-scheduler for php-resque, adding delayed job scheduling. Enqueue jobs to run at a future timestamp or after N seconds, compatible with the Ruby resque-scheduler web UI. Recurring/cron-style jobs not yet supported.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require david-garcia/php-resque-scheduler
    

    (Note: Due to the package being archived, verify compatibility with your PHP/Resque version.)

  2. Basic Configuration Add to your config/resque.php (or equivalent):

    'scheduler' => [
        'connection' => 'redis',
        'queue' => 'scheduler',
        'interval' => 60, // Seconds between checks
    ],
    
  3. First Use Case: Scheduling a Job

    use Resque\Job\Job;
    use DavidGarcia\ResqueScheduler\Scheduler;
    
    $scheduler = new Scheduler();
    $scheduler->schedule(
        new Job('queue:name', ['param1', 'param2']),
        now()->addMinutes(5)
    );
    

Where to Look First

  • Source Code: Focus on src/Scheduler.php for core logic.
  • Tests: Check tests/ for usage examples (if any).
  • Fork Differences: Compare with original repo to spot updates.

Implementation Patterns

Workflows

  1. Cron-Like Scheduling Replace cron jobs with PHP-based scheduling:

    $scheduler->schedule(
        new Job('process:invoices', ['user_id' => 123]),
        now()->addHour()
    );
    
  2. Recurring Jobs Use a loop to reschedule:

    $job = new Job('sync:data', []);
    $scheduler->schedule($job, now()->addMinutes(30));
    
    // Inside the job's `perform()`:
    $scheduler->schedule($job, now()->addMinutes(30));
    
  3. Dynamic Queues Route jobs to different queues based on conditions:

    $queue = $user->isPremium() ? 'premium' : 'standard';
    $scheduler->schedule(new Job("{$queue}:process", [...]), now());
    

Integration Tips

  • Laravel Integration: Use Laravel’s Artisan::queue() to wrap jobs:

    $scheduler->schedule(
        new Job('laravel:artisan', ['command' => 'queue:work']),
        now()->addSecond(10)
    );
    
  • Resque Worker Setup: Ensure your Resque worker processes the scheduler queue:

    resque -q scheduler,default
    
  • Logging: Extend Scheduler to log scheduled jobs:

    $scheduler->schedule($job, $time, function () {
        Log::info("Scheduled job {$job->getClass()}");
    });
    

Gotchas and Tips

Pitfalls

  1. Redis Connection Issues

    • Ensure Redis is running and accessible. Test with:
      Redis::connection()->ping();
      
    • Fix: Configure proper Redis host/port in config/resque.php.
  2. Timezone Mismatches

    • Jobs may run at unexpected times if timezones differ between server and scheduler.
    • Fix: Explicitly set timezone in app.php or use Carbon:
      $scheduler->schedule($job, Carbon::now('UTC')->addMinutes(5));
      
  3. Missing Dependencies

    • The package assumes Resque is installed (chrisboulton/php-resque).
    • Fix: Install Resque first:
      composer require chrisboulton/php-resque
      
  4. Archived Package Risks

    • No updates since 2017; may break with newer PHP/Resque.
    • Mitigation: Fork and maintain locally or use alternatives like spatie/laravel-scheduler.

Debugging Tips

  • Check Scheduled Jobs:
    $scheduledJobs = Redis::connection()->lrange('resque:scheduler', 0, -1);
    
  • Worker Logs: Run Resque with verbose logging:
    resque -v -q scheduler
    
  • Test Locally: Use a Dockerized Redis for isolation:
    # docker-compose.yml
    services:
      redis:
        image: redis
        ports: ["6379:6379"]
    

Extension Points

  1. Custom Storage Override getStorageKey() in Scheduler to use a custom Redis key.

  2. Job Validation Add pre-schedule validation:

    $scheduler->beforeSchedule(function (Job $job) {
        if (!$job->isValid()) {
            throw new \RuntimeException("Invalid job");
        }
    });
    
  3. Event Listeners Trigger events before/after scheduling:

    $scheduler->onSchedule(function (Job $job, \DateTime $time) {
        event(new JobScheduled($job, $time));
    });
    
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