Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@
|--------------------------------------------------------------------------
|
| Here you may configure the queue name and connection used when indexing
| documents.
| documents, along with a timeout (in seconds) for each indexing job.
|
*/

'queue' => env('STATAMIC_SEARCH_QUEUE'),

'queue_connection' => env('STATAMIC_SEARCH_QUEUE_CONNECTION'),

'queue_timeout' => env('STATAMIC_SEARCH_QUEUE_TIMEOUT'),

/*
|--------------------------------------------------------------------------
| Chunk Size
Expand Down
14 changes: 14 additions & 0 deletions src/Search/InsertMultipleJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ class InsertMultipleJob implements ShouldQueue
{
use Queueable;

/**
* The number of seconds the job can run before timing out.
*
* This needs to stay a property. Queue::createObjectPayload() reads it through
* getAttributeValue($job, Timeout::class, 'timeout'), which - unlike maxTries
* and backoff - has no method_exists() fallback, so a timeout() method here
* would be silently ignored.
*/
public ?int $timeout = null;

/**
* Create a new job instance.
*/
Expand All @@ -25,6 +35,10 @@ public function __construct(
) {
$this->onConnection($connection = config('statamic.search.queue_connection', config('queue.default')));
$this->onQueue(config('statamic.search.queue', config("queue.connections.{$connection}.queue")));

if (filled($timeout = config('statamic.search.queue_timeout'))) {
$this->timeout = (int) $timeout;
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/View/Cascade.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ public static function config(): array
'statamic.search.defaults',
'statamic.search.queue',
'statamic.search.queue_connection',
'statamic.search.queue_timeout',
'statamic.search.chunk_size',
'statamic.stache.watcher',
'statamic.stache.cache_store',
Expand Down
68 changes: 68 additions & 0 deletions tests/Search/InsertMultipleJobTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Tests\Search;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Search\InsertMultipleJob;
use Tests\TestCase;

class InsertMultipleJobTest extends TestCase
{
#[Test, DataProvider('timeoutProvider')]
public function it_sets_the_timeout_from_config($configured, $expected)
{
config(['statamic.search.queue_timeout' => $configured]);

$job = new InsertMultipleJob('test', null, collect(['entry::123']));

$this->assertSame($expected, $job->timeout);
}

public static function timeoutProvider()
{
return [
'not configured' => [null, null],
'empty env var' => ['', null],
'integer' => [300, 300],
'string from env' => ['300', 300],
];
}

#[Test, DataProvider('queueConnectionsProvider')]
public function it_uses_the_configured_queue_and_connection(
$configuredQueue,
$configuredConnection,
$defaultConnection,
$expectedJobQueue,
$expectedJobConnection
) {
config([
'statamic.search.queue' => $configuredQueue,
'statamic.search.queue_connection' => $configuredConnection,
'queue.default' => $defaultConnection,
]);

$job = new InsertMultipleJob('test', null, collect(['entry::123']));

$this->assertSame($expectedJobQueue, $job->queue);
$this->assertSame($expectedJobConnection, $job->connection);
}

/**
* When the config keys are null the job leaves connection/queue null rather than
* resolving them to the framework defaults, since config() only falls back to its
* second argument when a key is absent, and these keys always ship in the config
* file. A null connection/queue already means "use the default", so the outcome is
* the same - but the properties stay null.
*/
public static function queueConnectionsProvider()
{
return [
[null, null, 'redis', null, null],
['indexing', null, 'redis', 'indexing', null],
[null, 'sqs', 'redis', null, 'sqs'],
['indexing', 'sqs', 'redis', 'indexing', 'sqs'],
];
}
}
Loading