Skip to content

Conversation

guestpectacular
Copy link
Contributor

Carbon 3 Compatibility Fix for RedisJobRepository

Laravel Horizon uses Carbon's addMinutes() and subMinutes() methods throughout the RedisJobRepository class for job expiration and cleanup operations. These methods are called with configuration values retrieved via Laravel's config() helper.

The Problem:
Carbon 3 introduced stricter type checking and no longer accepts string values for time manipulation methods like addMinutes() and subMinutes(). The config() helper can return string values (especially when reading from environment variables), which causes type errors in Carbon 3.

The Solution:

This patch adds explicit integer casting (int) to all configuration values in the RedisJobRepository constructor:

  • horizon.trim.recent
  • horizon.trim.pending
  • horizon.trim.completed
  • horizon.trim.failed
  • horizon.trim.recent_failed
  • horizon.trim.monitored

Testing Examples:

Without this fix, the following common Laravel job operations would fail with Carbon 3:

  // Basic job dispatch - fails during job tracking/expiration
  TestJob::dispatch();

  // Delayed job dispatch - fails when setting pending job expiration
  TestJob::dispatch()->delay(now()->addMinutes(5));

  // Job with specific queue - fails during queue management
  TestJob::dispatch()->onQueue('emails');

  // Failed job handling - fails during failed job expiration tracking
  TestJob::dispatch()->onQueue('processing');

Error Example (before fix):
TypeError: Carbon\CarbonImmutable::addMinutes(): Argument #1 ($value) must be of type int, string given

Without the integer casting, Carbon 3 will throw type errors when these configuration values are strings, breaking job expiration, cleanup, and monitoring
functionality in Laravel Horizon.

This change maintains backward compatibility while ensuring Laravel Horizon works correctly with both Carbon 2 and Carbon 3, supporting Laravel 11's requirements.

@taylorotwell taylorotwell merged commit aabcd42 into laravel:5.x Aug 11, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants