Skip to content

feat(scout): fix queue configuration options#938

Closed
faraweilyas wants to merge 3 commits into
laravel:10.xfrom
faraweilyas:fix/fixes-queue-config-mixup
Closed

feat(scout): fix queue configuration options#938
faraweilyas wants to merge 3 commits into
laravel:10.xfrom
faraweilyas:fix/fixes-queue-config-mixup

Conversation

@faraweilyas

Copy link
Copy Markdown

Fix Scout queue configuration options

Description

This PR fixes Laravel Scout's queue configuration by expanding from a simple boolean flag to a nested array structure, allowing developers to specify custom queue connections and queue names while maintaining full backward compatibility.

Checkout the queue doc section to spot the bug.

Changes Made

  • Expand queue configuration structure: Changed from 'queue' => boolean to nested array with enable, connection, and queue options
  • Update queue checks in Searchable trait: Modified makeSearchable() and removeFromSearch() methods to use config()->boolean('scout.queue.enable') instead of config('scout.queue')
  • Add environment variable support: Introduced SCOUT_QUEUE_CONNECTION and SCOUT_QUEUE_NAME for easier configuration management
  • Update configuration comments: Revised inline comments to reflect the new structure and available options
  • Maintain backward compatibility: Existing SCOUT_QUEUE=true/false continues to work as expected

Benefits to End Users

  • Greater flexibility: Developers can now route Scout operations to specific queue connections (e.g., separate Redis instance for search indexing)
  • Better queue organization: Ability to use dedicated queue names for Scout operations, improving monitoring and job separation
  • Easier deployment management: Environment-based configuration makes it simple to use different queue setups across environments
  • Zero breaking changes: Existing applications continue to work without any code changes
  • More explicit configuration: Using config()->boolean() provides clearer intent and better type safety

Code Changes

config file updates:

// Before
'queue' => env('SCOUT_QUEUE', false),

// After
'queue' => [
    'enable' => env('SCOUT_QUEUE', false),
    'connection' => env('SCOUT_QUEUE_CONNECTION'),
    'queue' => env('SCOUT_QUEUE_NAME'),
],

Searchable trait updates:

// Before
if (! config('scout.queue')) {
    return $this->syncMakeSearchable($models);
}

// After  
if (! config()->boolean('scout.queue.enable')) {
    return $this->syncMakeSearchable($models);
}

// Before
if (! config('scout.queue')) {
    return $this->syncRemoveFromSearch($models);
}

// After  
if (! config()->boolean('scout.queue.enable')) {
    return $this->syncRemoveFromSearch($models);
}

- Change queue config from boolean to nested array structure
- Add configurable queue connection and queue name options
- Update comment to reflect new configuration format
- Maintain backward compatibility through environment variables

This allows for more granular control over Scout's queueing behavior
while keeping the same simple enable/disable functionality.
@taylorotwell

Copy link
Copy Markdown
Member

Seems like a breaking change with the way this is implemented.

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