Skip to content

Commit

Permalink
Add headers to SyncDriver (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
msmakouz committed May 8, 2024
1 parent 28dc7ea commit 02213d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Queue/src/Driver/SyncDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Spiral\Queue\Driver;

use Ramsey\Uuid\Uuid;
use Spiral\Queue\ExtendedOptionsInterface;
use Spiral\Queue\Interceptor\Consume\Handler;
use Spiral\Queue\OptionsInterface;
use Spiral\Queue\QueueInterface;
Expand Down Expand Up @@ -36,7 +37,8 @@ public function push(string $name, mixed $payload = [], OptionsInterface $option
driver: 'sync',
queue: 'default',
id: $id,
payload: $payload
payload: $payload,
headers: $options instanceof ExtendedOptionsInterface ? $options->getHeaders() : [],
);

return $id;
Expand Down
23 changes: 23 additions & 0 deletions src/Queue/tests/Driver/SyncDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Spiral\Core\CoreInterface;
use Spiral\Queue\Driver\SyncDriver;
use Spiral\Queue\Interceptor\Consume\Handler;
use Spiral\Queue\Options;
use Spiral\Telemetry\NullTracer;
use Spiral\Telemetry\NullTracerFactory;
use Spiral\Telemetry\TracerInterface;
Expand Down Expand Up @@ -64,6 +65,28 @@ public function testJobShouldBePushed(mixed $payload): void
$this->assertSame($uuid->toString(), $id);
}

public function testJobWithHeadersShouldBePushed(): void
{
$this->factory->shouldReceive('uuid4')
->andReturn($uuid = (new UuidFactory())->uuid4());

$options = (new Options())->withHeader('foo', 'bar');

$this->core->shouldReceive('callAction')
->withSomeOfArgs('foo', [
'driver' => 'sync',
'queue' => 'default',
'id' => $uuid->toString(),
'payload' => ['baz' => 'baf'],
'headers' => ['foo' => ['bar']]
])
->once();

$id = $this->queue->push('foo', ['baz' => 'baf'], $options);

$this->assertSame($uuid->toString(), $id);
}

public static function payloadDataProvider(): \Traversable
{
yield [['baz' => 'baf']];
Expand Down

0 comments on commit 02213d3

Please sign in to comment.