Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
{
"minimum-stability": "dev",
"prefer-stable": true,
"repositories": [
{
"type": "vcs",
"url": "https://github.com/temporalio/sdk-php"
}
],
"require": {
"spiral/tokenizer": "^3.16.0",
"temporal/sdk": "^2.16",
"temporal/sdk": "dev-nexus-new as 2.18.0",
"temporal/open-telemetry-interceptors": "^1.0",
"open-telemetry/exporter-otlp": "^1.3",
"open-telemetry/transport-grpc": "^1.1",
Expand All @@ -12,7 +18,8 @@
"require-dev": {
"buggregator/trap": "^1.15",
"internal/dload": "^1.8.0",
"phpunit/phpunit": "^10.5"
"phpunit/phpunit": "^10.5",
"phpstan/phpstan": "^2.2"
},
"autoload": {
"psr-4": {
Expand All @@ -33,6 +40,7 @@
},
"scripts": {
"get:binaries": "dload get --no-interaction -vv",
"test:feat": "phpunit --testsuite=Feature --color=always --testdox"
"test:feat": "phpunit --testsuite=Feature --color=always --testdox",
"phpstan": "phpstan analyse --memory-limit=2G"
}
}
893 changes: 523 additions & 370 deletions app/composer.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions app/src/Nexus/.rr.caller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3"

rpc:
listen: tcp://127.0.0.1:6102

server:
command: "php caller-worker.php"

temporal:
address: ${TEMPORAL_HOST:-localhost}:${TEMPORAL_PORT:-7233}
namespace: ${TEMPORAL_NAMESPACE:-my-caller-namespace}
activities:
num_workers: 2

logs:
level: info
16 changes: 16 additions & 0 deletions app/src/Nexus/.rr.handler.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3"

rpc:
listen: tcp://127.0.0.1:6101

server:
command: "php handler-worker.php"

temporal:
address: ${TEMPORAL_HOST:-localhost}:${TEMPORAL_PORT:-7233}
namespace: ${TEMPORAL_NAMESPACE:-my-target-namespace}
activities:
num_workers: 2

logs:
level: info
11 changes: 11 additions & 0 deletions app/src/Nexus/Caller/CallerWorker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Caller;

final class CallerWorker
{
public const TASK_QUEUE = 'my-caller-workflow-task-queue';
public const ENDPOINT_NAME = 'my-nexus-endpoint-name';
}
15 changes: 15 additions & 0 deletions app/src/Nexus/Caller/EchoCallerWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Caller;

use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[WorkflowInterface]
interface EchoCallerWorkflow
{
#[WorkflowMethod]
public function echo(string $message);
}
35 changes: 35 additions & 0 deletions app/src/Nexus/Caller/EchoCallerWorkflowImpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Caller;

use Carbon\CarbonInterval;
use Temporal\Samples\Nexus\Service\EchoInput;
use Temporal\Samples\Nexus\Service\EchoOutput;
use Temporal\Samples\Nexus\Service\SampleNexusService;
use Temporal\Workflow;
use Temporal\Workflow\NexusOperationOptions;

class EchoCallerWorkflowImpl implements EchoCallerWorkflow
{
/** @var SampleNexusService */
private object $sampleNexusService;

public function __construct()
{
$this->sampleNexusService = Workflow::newNexusServiceStub(
SampleNexusService::class,
NexusOperationOptions::new()
->withEndpoint(CallerWorker::ENDPOINT_NAME)
->withScheduleToCloseTimeout(CarbonInterval::seconds(10)),
);
}

public function echo(string $message)
{
/** @var EchoOutput $output */
$output = yield $this->sampleNexusService->echo(new EchoInput($message));
return $output->message;
}
}
16 changes: 16 additions & 0 deletions app/src/Nexus/Caller/HelloCallerWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Caller;

use Temporal\Samples\Nexus\Service\Language;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[WorkflowInterface]
interface HelloCallerWorkflow
{
#[WorkflowMethod]
public function hello(string $message, Language $language);
}
36 changes: 36 additions & 0 deletions app/src/Nexus/Caller/HelloCallerWorkflowImpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Caller;

use Carbon\CarbonInterval;
use Temporal\Samples\Nexus\Service\HelloInput;
use Temporal\Samples\Nexus\Service\HelloOutput;
use Temporal\Samples\Nexus\Service\Language;
use Temporal\Samples\Nexus\Service\SampleNexusService;
use Temporal\Workflow;
use Temporal\Workflow\NexusOperationOptions;

class HelloCallerWorkflowImpl implements HelloCallerWorkflow
{
/** @var SampleNexusService */
private object $sampleNexusService;

public function __construct()
{
$this->sampleNexusService = Workflow::newNexusServiceStub(
SampleNexusService::class,
NexusOperationOptions::new()
->withEndpoint(CallerWorker::ENDPOINT_NAME)
->withScheduleToCloseTimeout(CarbonInterval::seconds(10)),
);
}

public function hello(string $message, Language $language)
{
/** @var HelloOutput $output */
$output = yield $this->sampleNexusService->hello(new HelloInput($message, $language));
return $output->message;
}
}
16 changes: 16 additions & 0 deletions app/src/Nexus/Caller/HelloWithTokenCallerWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Caller;

use Temporal\Samples\Nexus\Service\Language;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[WorkflowInterface]
interface HelloWithTokenCallerWorkflow
{
#[WorkflowMethod]
public function hello(string $message, Language $language);
}
47 changes: 47 additions & 0 deletions app/src/Nexus/Caller/HelloWithTokenCallerWorkflowImpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Caller;

use Carbon\CarbonInterval;
use Temporal\Samples\Nexus\Service\HelloInput;
use Temporal\Samples\Nexus\Service\HelloOutput;
use Temporal\Samples\Nexus\Service\Language;
use Temporal\Workflow;
use Temporal\Workflow\NexusOperationHandle;
use Temporal\Workflow\NexusOperationOptions;
use Temporal\Workflow\NexusOperationStubInterface;

class HelloWithTokenCallerWorkflowImpl implements HelloWithTokenCallerWorkflow
{
private NexusOperationStubInterface $stub;

public function __construct()
{
$this->stub = Workflow::newUntypedNexusOperationStub(
NexusOperationOptions::new()
->withEndpoint(CallerWorker::ENDPOINT_NAME)
->withService('SampleNexusService')
->withScheduleToCloseTimeout(CarbonInterval::seconds(10)),
);
}

public function hello(string $message, Language $language)
{
/** @var NexusOperationHandle<HelloOutput> $handle */
$handle = yield $this->stub->start(
'hello',
[new HelloInput($message, $language)],
HelloOutput::class,
);

$token = $handle->getOperationToken() ?? '<sync>';
Workflow::getLogger()->info("Nexus operation started, token: {$token}");

/** @var HelloOutput $output */
$output = yield $handle->getResult();

return "[token={$token}] {$output->message}";
}
}
84 changes: 84 additions & 0 deletions app/src/Nexus/ExecuteCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Temporal\Samples\Nexus;

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Temporal\Client\ClientOptions as TemporalClientOptions;
use Temporal\Client\GRPC\ServiceClient;
use Temporal\Client\WorkflowClient;
use Temporal\Client\WorkflowOptions;
use Temporal\Samples\Nexus\Caller\CallerWorker;
use Temporal\Samples\Nexus\Caller\EchoCallerWorkflow;
use Temporal\Samples\Nexus\Caller\HelloCallerWorkflow;
use Temporal\Samples\Nexus\Caller\HelloWithTokenCallerWorkflow;
use Temporal\Samples\Nexus\Service\Language;
use Temporal\SampleUtils\Command;

class ExecuteCommand extends Command
{
protected const NAME = 'nexus';
protected const DESCRIPTION = 'Execute Nexus\\EchoCallerWorkflow + HelloCallerWorkflow + HelloWithTokenCallerWorkflow (cross-namespace via Nexus)';

public function execute(InputInterface $input, OutputInterface $output): int
{
$host = \getenv('TEMPORAL_ADDRESS') ?: \getenv('TEMPORAL_CLI_ADDRESS') ?: 'localhost:7233';
$client = WorkflowClient::create(
ServiceClient::create($host),
(new TemporalClientOptions())->withNamespace('my-caller-namespace'),
);

$output->writeln("Starting <comment>EchoCallerWorkflow</comment>...");
$echoWorkflow = $client->newWorkflowStub(
EchoCallerWorkflow::class,
WorkflowOptions::new()->withTaskQueue(CallerWorker::TASK_QUEUE),
);
$run = $client->start($echoWorkflow, 'Nexus Echo 👋');
$execution = $run->getExecution();
$output->writeln(\sprintf(
'Started: WorkflowID=<fg=magenta>%s</> RunID=<fg=magenta>%s</>',
$execution->getID(),
$execution->getRunID(),
));
$output->writeln(\sprintf("Result: <info>%s</info>", $run->getResult('string')));

$output->writeln("\nStarting <comment>HelloCallerWorkflow</comment>...");
$helloWorkflow = $client->newWorkflowStub(
HelloCallerWorkflow::class,
WorkflowOptions::new()->withTaskQueue(CallerWorker::TASK_QUEUE),
);
$run = $client->start($helloWorkflow, 'Nexus', Language::ES);
$execution = $run->getExecution();
$output->writeln(\sprintf(
'Started: WorkflowID=<fg=magenta>%s</> RunID=<fg=magenta>%s</>',
$execution->getID(),
$execution->getRunID(),
));
$output->writeln(\sprintf("Result: <info>%s</info>", $run->getResult('string')));

$output->writeln("\nStarting <comment>HelloWithTokenCallerWorkflow</comment>...");
$tokenWorkflow = $client->newWorkflowStub(
HelloWithTokenCallerWorkflow::class,
WorkflowOptions::new()->withTaskQueue(CallerWorker::TASK_QUEUE),
);
$run = $client->start($tokenWorkflow, 'Nexus', Language::FR);
$execution = $run->getExecution();
$output->writeln(\sprintf(
'Started: WorkflowID=<fg=magenta>%s</> RunID=<fg=magenta>%s</>',
$execution->getID(),
$execution->getRunID(),
));
$output->writeln(\sprintf("Result: <info>%s</info>", $run->getResult('string')));

return self::SUCCESS;
}
}
13 changes: 13 additions & 0 deletions app/src/Nexus/Handler/EchoClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Handler;

use Temporal\Samples\Nexus\Service\EchoInput;
use Temporal\Samples\Nexus\Service\EchoOutput;

interface EchoClient
{
public function echo(EchoInput $input): EchoOutput;
}
16 changes: 16 additions & 0 deletions app/src/Nexus/Handler/EchoClientImpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Handler;

use Temporal\Samples\Nexus\Service\EchoInput;
use Temporal\Samples\Nexus\Service\EchoOutput;

class EchoClientImpl implements EchoClient
{
public function echo(EchoInput $input): EchoOutput
{
return new EchoOutput($input->message);
}
}
10 changes: 10 additions & 0 deletions app/src/Nexus/Handler/HandlerWorker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Handler;

final class HandlerWorker
{
public const TASK_QUEUE = 'my-handler-task-queue';
}
16 changes: 16 additions & 0 deletions app/src/Nexus/Handler/HelloHandlerWorkflow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Temporal\Samples\Nexus\Handler;

use Temporal\Samples\Nexus\Service\HelloInput;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[WorkflowInterface]
interface HelloHandlerWorkflow
{
#[WorkflowMethod]
public function hello(HelloInput $input);
}
Loading