Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
bohanyang committed Aug 9, 2023
1 parent cd1b447 commit c9a57af
Show file tree
Hide file tree
Showing 13 changed files with 440 additions and 259 deletions.
8 changes: 1 addition & 7 deletions packages/mango/Bundle/MangoBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Manyou\Mango\Doctrine\Type\UuidType;
use Manyou\Mango\HttpKernel\AsDtoInitializer;
use Manyou\Mango\Scheduler\Messenger\RecurringScheduleMiddleware;
use Manyou\Mango\Scheduler\Messenger\ScheduledMessageMiddleware;
use Manyou\Mango\TaskQueue\Doctrine\Type\TaskStatusType;
use Manyou\Mango\TaskQueue\Messenger\Middleware\TaskQueueMiddware;
use ReflectionClass;
Expand Down Expand Up @@ -62,14 +61,9 @@ static function (ChildDefinition $definition, AsDtoInitializer $attribute, Refle
priority: 1,
);

$container->addCompilerPass(
new MessengerMiddlewarePass(['id' => ScheduledMessageMiddleware::class]),
priority: 2,
);

$container->addCompilerPass(
new MessengerMiddlewarePass(['id' => RecurringScheduleMiddleware::class]),
priority: 3,
priority: 2,
);

$container->addCompilerPass(
Expand Down
20 changes: 14 additions & 6 deletions packages/mango/Doctrine/SchemaProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,26 @@ public function getConnection(): Connection
public function transactional(Closure $func)
{
$this->connection->beginTransaction();
$commit = true;

try {
$res = $func($this);
$this->connection->commit();
$res = $func($this, $commit);
if ($commit) {
$this->connection->commit();
}

return $res;
} catch (Throwable $e) {
try {
$this->connection->rollBack();
} catch (PDOException) {
}
$commit = false;

throw $e;
} finally {
if (! $commit) {
try {
$this->connection->rollBack();
} catch (PDOException) {
}
}
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/mango/Doctrine/Type/BackedEnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use BackedEnum;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Types\ConversionException;
use LogicException;

Expand All @@ -19,6 +20,8 @@ trait BackedEnumType
convertToDatabaseValue as doConvertToDatabaseValue;
}

abstract private function getName(): string;

abstract private function getEnumClass(): string;

private function getEnums(): array
Expand Down Expand Up @@ -56,4 +59,13 @@ public function convertToPHPValue($value, AbstractPlatform $platform): ?BackedEn

return $this->getEnumClass()::from($value);
}

public function getMappedDatabaseTypes(AbstractPlatform $platform): array
{
if ($platform instanceof PostgreSQLPlatform) {
return [$this->getName()];
}

return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\Types\Types;
use Manyou\Mango\Doctrine\Contract\TableProvider;
use Manyou\Mango\Doctrine\Table;
use Manyou\Mango\Doctrine\Type\UsDateTimeImmutableType;

class ScheduledMessagesTable implements TableProvider
{
Expand All @@ -18,11 +17,9 @@ public function __invoke(Schema $schema): Table
{
$table = new Table($schema, self::NAME);
$table->addColumn('key', Types::STRING);
$table->addColumn('envelope', Types::JSON)->setPlatformOptions(['jsonb' => true]);
$table->addColumn('available_at', Types::DATETIME_IMMUTABLE, alias: 'availableAt');
$table->addColumn('last_dispatched_at', UsDateTimeImmutableType::NAME, ['notnull' => false], alias: 'lastDispatchedAt');
$table->addColumn('message_id', Types::BIGINT, alias: 'messageId');
$table->setPrimaryKey(['key']);
$table->addIndex(['available_at']);
$table->addUniqueIndex(['message_id']);

return $table;
}
Expand Down
24 changes: 0 additions & 24 deletions packages/mango/Scheduler/Doctrine/Table/SchedulerTriggersTable.php

This file was deleted.

9 changes: 0 additions & 9 deletions packages/mango/Scheduler/Message/SchedulerTrigger.php

This file was deleted.

54 changes: 0 additions & 54 deletions packages/mango/Scheduler/Message/SchedulerTriggerHandler.php

This file was deleted.

46 changes: 46 additions & 0 deletions packages/mango/Scheduler/Messenger/ScheduleMessageStamp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Manyou\Mango\Scheduler\Messenger;

use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;

class ScheduleMessageStamp implements NonSendableStampInterface
{
private function __construct(
public readonly string $key,
public readonly string $action,
) {
}

public static function insert(string $key): self
{
return new self($key, 'insert');
}

public static function update(string $key): self
{
return new self($key, 'update');
}

public static function upsert(string $key): self
{
return new self($key, 'upsert');
}

public function isUpdate(): bool
{
return 'update' === $this->action;
}

public function isUpsert(): bool
{
return 'upsert' === $this->action;
}

public function isInsert(): bool
{
return 'insert' === $this->action;
}
}
50 changes: 0 additions & 50 deletions packages/mango/Scheduler/Messenger/ScheduledMessageMiddleware.php

This file was deleted.

20 changes: 0 additions & 20 deletions packages/mango/Scheduler/Messenger/ScheduledMessageStamp.php

This file was deleted.

Loading

0 comments on commit c9a57af

Please sign in to comment.