Skip to content

Commit

Permalink
saga
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro-yakovlev committed Feb 21, 2024
1 parent 2bf458a commit 03c8e8f
Show file tree
Hide file tree
Showing 174 changed files with 4,294 additions and 239 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ db_schema_validate:
${DOCKER_COMPOSE} exec -u www-data php-fpm bin/console doctrine:schema:validate

db_migration_down:
${DOCKER_COMPOSE} exec -u www-data php-fpm bin/console doctrine:migrations:execute "App\Shared\Infrastructure\Database\Migrations\Version********" --down --dry-run
${DOCKER_COMPOSE} exec -u www-data php-fpm bin/console doctrine:migrations:execute "App\Shared\Infrastructure\Database\Migrations\Version20240201164919" --down --dry-run

db_drop:
docker-compose -f ./docker/docker-compose.yml exec -u www-data php-fpm bin/console doctrine:schema:drop --force
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@
- [X] [Gitlab CI/CD](https://docs.gitlab.com/ee/ci/yaml/)
- [X] [GitHub Actions](https://docs.github.com/en/actions/quickstart)

Документация [в разработке](docs/index.md).
Документация [в разработке](docs/index.md).


// Добавить слушатели REJECTED и CONFIRMED методов в orders контексте.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"symfony/twig-bundle": "^6.4",
"symfony/uid": "^6.4",
"symfony/validator": "^6.4",
"symfony/workflow": "6.*",
"symfony/yaml": "^6.4",
"webmozart/assert": "^1.11"
},
Expand Down
90 changes: 89 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ doctrine:
dir: '%kernel.project_dir%/src/Payments/Infrastructure/ORM/Aggregate'
prefix: 'App\Payments\Domain\Aggregate'
alias: Payment
Inventory:
is_bundle: false
type: xml
dir: '%kernel.project_dir%/src/Inventory/Infrastructure/ORM/Aggregate'
prefix: 'App\Inventory\Domain\Aggregate'
alias: Inventory
Saga:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Saga'
prefix: 'App\Saga'
alias: Saga

#when@test:
# doctrine:
Expand Down
59 changes: 52 additions & 7 deletions config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,34 @@ framework:
table_name: 'orders_outbox_message'
use_notify: true
auto_setup: true
# failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'
check_delayed_interval: 1000
inventory_outbox:
dsn: '%env(DOCTRINE_MESSENGER_TRANSPORT_DSN)%'
options:
table_name: 'inventory_outbox_message'
use_notify: true
auto_setup: true
check_delayed_interval: 1000
payments_outbox:
dsn: '%env(DOCTRINE_MESSENGER_TRANSPORT_DSN)%'
options:
table_name: 'payments_outbox_message'
use_notify: true
auto_setup: true
check_delayed_interval: 1000
saga:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
serializer: 'App\Saga\Event\EventEnvelopeSerializer'
options:
exchange:
name: 'saga'
type: 'topic'
queues:
saga:
binding_keys:
- 'payments.#'
- 'inventory.#'
- 'orders.#'
orders:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
serializer: 'App\Orders\Infrastructure\Event\EventEnvelopeSerializer'
Expand All @@ -34,11 +60,26 @@ framework:
queues:
orders:
binding_keys:
- 'payments.#'
- 'inventory.#'
- 'orders.#'
inventory:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
serializer: 'App\Inventory\Infrastructure\Event\EventEnvelopeSerializer'
# retry_strategy:
# max_retries: 3
# delay: 1000
# multiplier: 2
options:
exchange:
name: 'inventory'
type: 'topic'
queues:
inventory:
binding_keys:
- 'payments.#'
# arguments:
# x-max-length: 10000
# x-overflow: reject-publish
- 'inventory.#'
- 'orders.#'
payments:
dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
serializer: 'App\Payments\Infrastructure\Event\EventEnvelopeSerializer'
Expand All @@ -50,9 +91,13 @@ framework:
payments:
binding_keys:
- 'payments.#'
- 'inventory.#'
- 'orders.#'

routing:
'App\Orders\Infrastructure\Event\EventEnvelope': [orders, payments, inventory, saga]
'App\Orders\Infrastructure\Event\Outbox\OutboxMessage': orders_outbox
'App\Orders\Infrastructure\Event\EventEnvelope': [orders, payments]
'App\Payments\Infrastructure\Event\EventEnvelope': [orders, payments]
'App\Payments\Infrastructure\Event\EventEnvelope': [orders, payments, inventory, saga]
'App\Payments\Infrastructure\Event\Outbox\OutboxMessage': payments_outbox
'App\Inventory\Infrastructure\Event\EventEnvelope': [orders, payments, inventory, saga]
'App\Inventory\Infrastructure\Event\Outbox\OutboxMessage': inventory_outbox
48 changes: 48 additions & 0 deletions config/packages/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
framework:
workflows:
create_order:
type: 'state_machine'
# marking_store:
# type: 'method'
# property: 'state'
marking_store:
service: App\Saga\CreateOrder\SagaMarkingStore
supports:
- App\Saga\CreateOrder\Entity\CreateOrderSagaEntity
initial_marking: reservation_pending
places:
reservation_pending: ~
reservation_rejected: ~
reservation_confirmed: ~

payment_pending: ~
payment_rejected: ~
payment_confirmed: ~

order_completed: ~
order_cancelled: ~
transitions:
confirm_reservation:
from: reservation_pending
to: reservation_confirmed
reject_reservation:
from: reservation_pending
to: reservation_rejected

pay_order:
from: reservation_confirmed
to: payment_pending
confirm_payment:
from: payment_pending
to: payment_confirmed
reject_payment:
from: payment_pending
to: payment_rejected

complete:
from: payment_confirmed
to: order_completed

cancel:
from: [reservation_rejected, payment_rejected]
to: order_cancelled
12 changes: 12 additions & 0 deletions deptrac-modules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ parameters:
collectors:
- type: directory
regex: /src/Payments/.*
- name: Inventory
collectors:
- type: directory
regex: /src/Inventory/.*
- name: Saga
collectors:
- type: directory
regex: /src/Saga/.*
ruleset:
Skills:
- Shared
Expand All @@ -46,3 +54,7 @@ parameters:
- Shared
Payments:
- Shared
Inventory:
- Shared
Saga:
- Shared
3 changes: 3 additions & 0 deletions docker/php-fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ RUN apk add --no-cache rabbitmq-c-dev \
RUN apk add --no-cache supervisor
COPY ./docker/php-fpm/supervisord.conf /etc/supervisord.conf

# Graphviz, provides the dot command (Symfony Workflow component)
RUN apk add --no-cache graphviz ttf-freefont

# Source code
RUN chown www-data:www-data /var/www
COPY --chown=www-data:www-data ./ /var/www
Expand Down
14 changes: 13 additions & 1 deletion docker/php-fpm/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ user=www-data
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
stderr_logfile_maxbytes=0

;[program:messenger-consume]
;command=php bin/console messenger:consume orders_outbox inventory_outbox payments_outbox saga orders inventory payments
;autostart=true
;autorestart=true
;priority=20
;startretries=1
;user=www-data
;stdout_logfile=/dev/stdout
;stdout_logfile_maxbytes=0
;stderr_logfile=/dev/stderr
;stderr_logfile_maxbytes=0
30 changes: 30 additions & 0 deletions src/Console/TestCompletePaymentConsoleCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace App\Console;

use App\Payments\Application\UseCase\PaymentsUseCaseInteractor;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
name: 'payments:test',
)]
final class TestCompletePaymentConsoleCommand extends Command
{
public function __construct(
private PaymentsUseCaseInteractor $paymentsUseCaseInteractor,
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->paymentsUseCaseInteractor->completePayment('ff1605cadc83ee2595f4f27bd70a3609');

return Command::SUCCESS;
}
}
Loading

0 comments on commit 03c8e8f

Please sign in to comment.