Skip to content

Commit

Permalink
feat: workflow example
Browse files Browse the repository at this point in the history
  • Loading branch information
lotyp committed Nov 20, 2024
1 parent fc94dae commit 26cb526
Show file tree
Hide file tree
Showing 26 changed files with 644 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, sockets, decimal
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, sockets, decimal, grpc
ini-values: error_reporting=E_ALL
coverage: none
tools: phive
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/dependency-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, sockets, decimal
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, sockets, decimal, grpc
ini-values: error_reporting=E_ALL
coverage: none
tools: phive
Expand Down Expand Up @@ -109,7 +109,7 @@ jobs:
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, sockets, decimal
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, sockets, decimal, grpc
ini-values: error_reporting=E_ALL
coverage: none
tools: phive
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/refactoring.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, sockets, decimal
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, sockets, decimal, grpc
ini-values: error_reporting=E_ALL
coverage: none

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, sockets, decimal
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, sockets, decimal, grpc
ini-values: error_reporting=E_ALL
coverage: none

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, opcache, pcntl, posix, sockets, decimal
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, curl, fileinfo, pdo_mysql, opcache, pcntl, posix, sockets, decimal, grpc
ini-values: error_reporting=E_ALL
coverage: none

Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, pdo_mysql, curl, fileinfo, opcache, pcntl, posix, sockets, decimal
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, pdo_mysql, curl, fileinfo, opcache, pcntl, posix, sockets, decimal, grpc
ini-values: error_reporting=E_ALL
coverage: xdebug

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php-version }}
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, pdo_mysql, pdo_sqlite, curl, fileinfo, opcache, pcntl, posix, sockets, decimal
extensions: none, ctype, dom, json, mbstring, simplexml, tokenizer, xml, xmlwriter, pdo, pdo_mysql, pdo_sqlite, curl, fileinfo, opcache, pcntl, posix, sockets, decimal, grpc
ini-values: error_reporting=E_ALL
coverage: xdebug

Expand Down
2 changes: 2 additions & 0 deletions app/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"ext-mbstring": "*",
"ext-pdo": "*",
"ext-sockets": "*",
"ext-grpc": "*",
"beberlei/assert": "^3.3",
"cycle/annotated": "^4.2",
"cycle/database": "^2.11",
Expand All @@ -52,6 +53,7 @@
"spiral-packages/laravel-validator": "^1.1",
"spiral-packages/league-event": "^1.0",
"spiral-packages/scheduler": "^2.3",
"spiral-packages/swagger-php": "^1.0",
"spiral-packages/yii-error-handler-bridge": "^1.1",
"spiral/cycle-bridge": "^2.10",
"spiral/data-grid-bridge": "^3.0",
Expand Down
147 changes: 145 additions & 2 deletions app/composer.lock

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

39 changes: 39 additions & 0 deletions app/src/Application/Transfer/DTO/TransferDetails.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Application\Transfer\DTO;

use OpenApi\Attributes as OAT;

class TransferDetails
{
#[OAT\Property(format: 'string', example: '10ab5df0-693a-4cd8-8ed5-1e702947d4d0')]
public string $transferId;

#[OAT\Property(format: 'string', example: '10ab5df0-693a-4cd8-8ed5-1e702947d4d0')]
public string $fromUserId;

#[OAT\Property(format: 'string', example: '10ab5df0-693a-4cd8-8ed5-1e702947d4d0')]
public string $toUserId;

#[OAT\Property(format: 'string', example: 'https://wayof.dev')]
public string $fromDomain;

#[OAT\Property(format: 'string', example: 'https://your-dev.way')]
public string $toDomain;

public function __construct(
string $transferId,
string $fromUserId,
string $toUserId,
string $fromDomain,
string $toDomain,
) {
$this->transferId = $transferId;
$this->fromUserId = $fromUserId;
$this->toUserId = $toUserId;
$this->fromDomain = $fromDomain;
$this->toDomain = $toDomain;
}
}
33 changes: 33 additions & 0 deletions app/src/Bridge/Spiral/Console/TransferCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Bridge\Spiral\Console;

use Application\Transfer\DTO\TransferDetails;
use Infrastructure\Temporal\Transfer\Workflows\TransferWebsiteWorkflowStub;
use Spiral\Console\Attribute\AsCommand;
use Spiral\Console\Command;
use Temporal\Client\WorkflowClientInterface;

/**
* @psalm-suppress PropertyNotSetInConstructor
*/
#[AsCommand(name: 'website:transfer', description: 'Transfer website from source to destination')]
class TransferCommand extends Command
{
public function __invoke(WorkflowClientInterface $workflow): int
{
$transferDetails = new TransferDetails(
transferId: '10ab5df0-693a-4cd8-8ed5-1e702947d4d0',
fromUserId: '10ab5df0-693a-4cd8-8ed5-1e702947d4d0',
toUserId: '10ab5df0-693a-4cd8-8ed5-1e702947d4d0',
fromDomain: 'https://wayof.dev',
toDomain: 'https://your-dev.way'
);

TransferWebsiteWorkflowStub::handle($workflow, $transferDetails);

return self::SUCCESS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Domain\Transfer\Contracts;

use Application\Transfer\DTO\TransferDetails;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[WorkflowInterface]
interface TransferWebsiteWorkflowInterface
{
#[WorkflowMethod(name: 'website.transfer')]
public function handle(TransferDetails $transferDetails);

Check failure on line 15 in app/src/Domain/Transfer/Contracts/TransferWebsiteWorkflowInterface.php

View workflow job for this annotation

GitHub Actions / deptrac (ubuntu-latest, 8.3, locked)

Domain\Transfer\Contracts\TransferWebsiteWorkflowInterface must not depend on Application\Transfer\DTO\TransferDetails (Domain on Application)

Check failure on line 15 in app/src/Domain/Transfer/Contracts/TransferWebsiteWorkflowInterface.php

View workflow job for this annotation

GitHub Actions / deptrac (ubuntu-latest, 8.3, locked)

Infrastructure\Temporal\Transfer\Workflows\TransferWebsiteWorkflow must not depend on Application\Transfer\DTO\TransferDetails (Infrastructure on Application) Domain\Transfer\Contracts\TransferWebsiteWorkflowInterface::13 -> Application\Transfer\DTO\TransferDetails::15
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Infrastructure\Temporal\Transfer\Activities\Destination;

use Ramsey\Uuid\Uuid;
use Temporal\Activity\ActivityInterface;

use function sleep;

#[ActivityInterface(prefix: 'website.transfer.destination.')]
final readonly class AllocateSpaceActivity
{
public function handle(): string
{
// Simulate long-running Amazon Block Storage allocation
sleep(5);

return Uuid::uuid7()->toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Infrastructure\Temporal\Transfer\Activities\Destination;

use Ramsey\Uuid\Uuid;
use Temporal\Activity\ActivityInterface;

use function sleep;

#[ActivityInterface(prefix: 'website.transfer.destination.')]
final readonly class AttachDomainActivity
{
public function handle(): string
{
// Attach domain in destination
sleep(5);

return Uuid::uuid7()->toString();
}
}
Loading

0 comments on commit 26cb526

Please sign in to comment.