Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Apr 22, 2024
1 parent 9121a93 commit 598e5af
Show file tree
Hide file tree
Showing 50 changed files with 361 additions and 553 deletions.
10 changes: 8 additions & 2 deletions databox/api/config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,22 @@ framework:

routing:
Alchemy\ESBundle\Message\ESIndex: p1
Alchemy\Workflow\Message\JobConsumer: p1
buses:
command_bus:
middleware:
- doctrine_ping_connection

when@dev: &dev
when@dev:
framework:
messenger:
transports:
p1: 'sync://'
p2: 'sync://'

when@test: *dev
when@test:
framework:
messenger:
transports:
p1: 'test://'
p2: 'test://'
2 changes: 0 additions & 2 deletions databox/api/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ services:
_instanceof:
Alchemy\Workflow\Executor\Action\ActionInterface:
tags: ['alchemy_workflow.action']
Arthem\Bundle\RabbitBundle\Consumer\Event\EventMessageHandlerInterface:
tags: ['arthem_rabbit.event_handler']
Symfony\Component\EventDispatcher\EventSubscriberInterface:
tags: ['kernel.event_subscriber']
App\Attribute\Type\AttributeTypeInterface:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Border\Consumer\Handler\Uploader;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class UploaderNewCommit
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/Asset/AssetCopy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Asset;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class AssetCopy
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/Asset/AssetDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Asset;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class AssetDelete
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/Asset/AssetMove.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Asset;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
readonly class AssetMove
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/Asset/AttributeChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Asset;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class AttributeChanged
{
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Collection;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class DeleteCollection
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/File/CopyFileToAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\File;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class CopyFileToAsset
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/File/CopyFileToRendition.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\File;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class CopyFileToRendition
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/File/FileDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\File;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p2')]
final readonly class FileDelete
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/File/ImportFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\File;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class ImportFile
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/File/NewAssetFromBorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\File;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class NewAssetFromBorder
{
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Phraseanet;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class PhraseanetDownloadSubdef
{
public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/Search/ESPopulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Search;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p2')]
final readonly class ESPopulate
{
}
3 changes: 3 additions & 0 deletions databox/api/src/Consumer/Handler/Search/IndexAllAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Search;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class IndexAllAssets
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Search;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class IndexAllCollections
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Search;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class IndexCollectionBranch
{
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Search\Mapping;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class UpdateAttributesMapping
{
public function __construct(private string $id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Workspace;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p2')]
final readonly class DeleteWorkspace
{
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Consumer\Handler\Workspace;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class OnWorkspaceDelete
{
public function __construct(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Integration\Aws\Transcribe\Consumer;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class AwsTranscribeEvent
{
public function __construct(private string $integrationId, private string $body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __invoke(AwsTranscribeEvent $message): void
if ('Notification' === $payload['Type']) {
$msg = json_decode($payload['Message'], true, 512, JSON_THROW_ON_ERROR);

if ('aws.transcribe' === $message['source']) {
if ('aws.transcribe' === $msg['source']) {
$this->bus->dispatch(new TranscribeJobStatusChanged(
$workspaceIntegration->getId(),
$msg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Integration\Aws\Transcribe\Consumer;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class ConfirmSnsSubscription
{
public function __construct(private string $url)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Integration\Aws\Transcribe\Consumer;

use Alchemy\MessengerBundle\Attribute\MessengerMessage;

#[MessengerMessage('p1')]
final readonly class TranscribeJobStatusChanged
{
public function __construct(private string $integrationId, private array $message)
{
}

public function getIntegrationId(): string
{
return $this->integrationId;
}

public function getMessage(): array
{
return $this->message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace App\Integration\Aws\Transcribe\Consumer;

use App\Integration\IntegrationManager;
use Arthem\Bundle\RabbitBundle\Consumer\Event\AbstractEntityManagerHandler;
use Arthem\Bundle\RabbitBundle\Consumer\Event\EventMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler]
Expand Down Expand Up @@ -100,20 +98,3 @@ public function __invoke(TranscribeJobStatusChanged $message): void
*/
}
}

final readonly class TranscribeJobStatusChanged
{
public function __construct(private string $integrationId, private array $message)
{
}

public function getIntegrationId(): string
{
return $this->integrationId;
}

public function getMessage(): array
{
return $this->message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use App\Entity\Integration\IntegrationData;
use App\Entity\Integration\WorkspaceIntegration;
use App\Integration\Aws\Transcribe\AwsTranscribeIntegration;
use App\Integration\Aws\Transcribe\Consumer\AwsTranscribeEvent;
use App\Integration\Aws\Transcribe\Consumer\AwsTranscribeEventHandler;
use Arthem\Bundle\RabbitBundle\Producer\EventProducer;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

Expand All @@ -29,6 +29,8 @@ public function testSubscriptionUrlWillBeConfirmed(): void
$apiClient = static::createClient();
$apiClient->disableReboot();

$inMemoryTransport = $this->interceptMessengerEvents();

$wsIntegration = $this->createIntegration();

$payload = <<<EOL
Expand All @@ -48,6 +50,11 @@ public function testSubscriptionUrlWillBeConfirmed(): void

$this->triggerEvent($apiClient, $wsIntegration->getId(), $payload);
$this->assertResponseStatusCodeSame(200);

$envelope = $inMemoryTransport->getSent()[0];
self::assertInstanceOf(AwsTranscribeEvent::class, $envelope->getMessage());
$this->consumeEvent($envelope);

$this->assertHasData($wsIntegration->getId(), AwsTranscribeEventHandler::DATA_EVENT_MESSAGE, 1);
}

Expand Down Expand Up @@ -111,8 +118,7 @@ public function testNotificationWillBeHandled(): void
{
self::enableFixtures();

$eventProducer = self::getService(EventProducer::class);
$eventProducer->interceptEvents();
$inMemoryTransport = $this->interceptMessengerEvents();

$apiClient = static::createClient();
$apiClient->disableReboot();
Expand All @@ -136,9 +142,9 @@ public function testNotificationWillBeHandled(): void
$this->triggerEvent($apiClient, $wsIntegration->getId(), $payload);
$this->assertResponseStatusCodeSame(200);

$eventMessage = $eventProducer->shiftEvent();
self::assertEquals(AwsTranscribeEventHandler::EVENT, $eventMessage->getType());
$this->consumeEvent($eventMessage);
$envelope = $inMemoryTransport->get()[0];
self::assertInstanceOf(AwsTranscribeEvent::class, $envelope->getMessage());
$this->consumeEvent($envelope);

$this->assertHasData($wsIntegration->getId(), AwsTranscribeEventHandler::DATA_EVENT_MESSAGE, 1);
}
Expand Down
Loading

0 comments on commit 598e5af

Please sign in to comment.