Skip to content

Commit

Permalink
Merge pull request #63 from msmakouz/feature/interceptors
Browse files Browse the repository at this point in the history
Adding interceptors support
  • Loading branch information
roxblnfk committed Apr 24, 2023
2 parents b37149a + 2def9d1 commit c555447
Show file tree
Hide file tree
Showing 17 changed files with 470 additions and 164 deletions.
27 changes: 15 additions & 12 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
on:
push:
branches:
- master
pull_request: null
push:
branches:
- master
- '*.*'

name: phpunit

jobs:
phpunit:
uses: spiral/gh-actions/.github/workflows/phpunit.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2']
stability: >-
['prefer-stable']
phpunit:
uses: spiral/gh-actions/.github/workflows/phpunit.yml@master
with:
extensions: sockets, grpc
os: >-
['ubuntu-latest']
php: >-
['8.1', '8.2']
stability: >-
['prefer-stable']
22 changes: 12 additions & 10 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
on:
push:
branches:
- master
pull_request: null
push:
branches:
- master
- '*.*'

name: static analysis

jobs:
psalm:
uses: spiral/gh-actions/.github/workflows/psalm.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.1']
psalm:
uses: spiral/gh-actions/.github/workflows/psalm.yml@master
with:
os: >-
['ubuntu-latest']
php: >-
['8.1']
54 changes: 0 additions & 54 deletions .github/workflows/run-tests.yml

This file was deleted.

51 changes: 0 additions & 51 deletions .github/workflows/static-analysis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"spiral/tokenizer": "^3.0",
"spiral/roadrunner-bridge": "^2.0 || ^3.0",
"nette/php-generator": "^4.0",
"temporal/sdk": "^1.3 || ^2.0"
"temporal/sdk": "dev-interceptors"
},
"require-dev": {
"spiral/framework": "^3.0",
Expand Down
29 changes: 13 additions & 16 deletions src/Bootloader/TemporalBridgeBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Spiral\Boot\AbstractKernel;
use Spiral\Boot\Bootloader\Bootloader;
use Spiral\Boot\EnvironmentInterface;
use Spiral\Boot\FinalizerInterface;
use Spiral\Config\ConfiguratorInterface;
use Spiral\Config\Patch\Append;
use Spiral\Console\Bootloader\ConsoleBootloader;
Expand All @@ -20,6 +19,8 @@
use Spiral\TemporalBridge\Dispatcher;
use Spiral\TemporalBridge\Preset\PresetRegistry;
use Spiral\TemporalBridge\Preset\PresetRegistryInterface;
use Spiral\TemporalBridge\WorkerFactory;
use Spiral\TemporalBridge\WorkerFactoryInterface;
use Spiral\TemporalBridge\WorkersRegistry;
use Spiral\TemporalBridge\WorkersRegistryInterface;
use Spiral\TemporalBridge\Workflow\WorkflowManager;
Expand All @@ -33,22 +34,26 @@
use Temporal\Client\WorkflowClientInterface;
use Temporal\DataConverter\DataConverter;
use Temporal\DataConverter\DataConverterInterface;
use Temporal\Interceptor\SimplePipelineProvider;
use Temporal\Interceptor\PipelineProvider;
use Temporal\Worker\Transport\Goridge;
use Temporal\Worker\WorkerFactoryInterface;
use Temporal\Worker\WorkerFactoryInterface as TemporalWorkerFactoryInterface;
use Temporal\Worker\WorkerOptions;
use Temporal\WorkerFactory;
use Temporal\WorkerFactory as TemporalWorkerFactory;

class TemporalBridgeBootloader extends Bootloader
{
protected const SINGLETONS = [
WorkflowPresetLocatorInterface::class => [self::class, 'initWorkflowPresetLocator'],
WorkflowManagerInterface::class => WorkflowManager::class,
WorkerFactoryInterface::class => [self::class, 'initWorkerFactory'],
TemporalWorkerFactoryInterface::class => [self::class, 'initWorkerFactory'],
DeclarationLocatorInterface::class => [self::class, 'initDeclarationLocator'],
WorkflowClientInterface::class => [self::class, 'initWorkflowClient'],
WorkersRegistryInterface::class => [self::class, 'initWorkersRegistry'],
WorkersRegistryInterface::class => WorkersRegistry::class,
PresetRegistryInterface::class => PresetRegistry::class,
DataConverterInterface::class => [self::class, 'initDataConverter'],
WorkerFactoryInterface::class => WorkerFactory::class,
PipelineProvider::class => SimplePipelineProvider::class,
];

protected const DEPENDENCIES = [
Expand Down Expand Up @@ -99,7 +104,7 @@ protected function initConfig(EnvironmentInterface $env): void
[
'address' => $env->get('TEMPORAL_ADDRESS', '127.0.0.1:7233'),
'namespace' => 'App\\Workflow',
'defaultWorker' => (string)$env->get('TEMPORAL_TASK_QUEUE', WorkerFactoryInterface::DEFAULT_TASK_QUEUE),
'defaultWorker' => (string)$env->get('TEMPORAL_TASK_QUEUE', TemporalWorkerFactory::DEFAULT_TASK_QUEUE),
'workers' => [],
]
);
Expand All @@ -123,8 +128,8 @@ protected function initDataConverter(): DataConverterInterface

protected function initWorkerFactory(
DataConverterInterface $dataConverter
): WorkerFactoryInterface {
return new WorkerFactory(
): TemporalWorkerFactoryInterface {
return new TemporalWorkerFactory(
dataConverter: $dataConverter,
rpc: Goridge::create()
);
Expand All @@ -138,12 +143,4 @@ classes: $classes,
reader: new AttributeReader()
);
}

protected function initWorkersRegistry(
WorkerFactoryInterface $workerFactory,
FinalizerInterface $finalizer,
TemporalConfig $config
): WorkersRegistryInterface {
return new WorkersRegistry($workerFactory, $finalizer, $config);
}
}
7 changes: 6 additions & 1 deletion src/Commands/MakePresetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
use Spiral\TemporalBridge\Generator\Generator;
use Spiral\TemporalBridge\Preset\PresetRegistryInterface;
use Spiral\TemporalBridge\WorkflowPresetLocatorInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

final class MakePresetCommand extends Command
{
use WithContext;

protected const SIGNATURE = 'temporal:make-preset {preset : Workflow preset} {name : Workflow name}';
protected const NAME = 'temporal:make-preset';
protected const DESCRIPTION = 'Make a new Temporal workflow preset';
protected const ARGUMENTS = [
['name', InputArgument::REQUIRED, 'Workflow name'],
['preset', InputArgument::REQUIRED, 'Workflow preset'],
];

public function perform(
Generator $generator,
Expand Down
6 changes: 5 additions & 1 deletion src/Commands/MakeWorkflowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@
use Spiral\TemporalBridge\Generator\HandlerInterfaceGenerator;
use Spiral\TemporalBridge\Generator\WorkflowGenerator;
use Spiral\TemporalBridge\Generator\WorkflowInterfaceGenerator;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;

final class MakeWorkflowCommand extends Command
{
use WithContext;

protected const SIGNATURE = 'temporal:make-workflow {name : Workflow name}';
protected const NAME = 'temporal:make-workflow';
protected const DESCRIPTION = 'Make a new Temporal workflow';
protected const ARGUMENTS = [
['name', InputArgument::REQUIRED, 'Workflow name'],
];

public function perform(Generator $generator): int
{
Expand Down
38 changes: 36 additions & 2 deletions src/Config/TemporalConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,30 @@

namespace Spiral\TemporalBridge\Config;

use Spiral\Core\Container\Autowire;
use Spiral\Core\InjectableConfig;
use Temporal\Exception\ExceptionInterceptorInterface;
use Temporal\Internal\Interceptor\Interceptor;
use Temporal\Worker\WorkerFactoryInterface;
use Temporal\Worker\WorkerOptions;

/**
* @psalm-type TInterceptor = Interceptor|class-string<Interceptor>|Autowire<Interceptor>
* @psalm-type TExceptionInterceptor = ExceptionInterceptorInterface|class-string<ExceptionInterceptorInterface>|Autowire<ExceptionInterceptorInterface>
* @psalm-type TWorker = array{
* options?: WorkerOptions,
* interceptors?: TInterceptor[],
* exception_interceptor?: TExceptionInterceptor
* }
*
* @property array{
* address: non-empty-string,
* namespace: non-empty-string,
* temporalNamespace: non-empty-string,
* defaultWorker: non-empty-string,
* workers: array<non-empty-string, WorkerOptions|TWorker>
* } $config
*/
final class TemporalConfig extends InjectableConfig
{
public const CONFIG = 'temporal';
Expand All @@ -20,29 +40,43 @@ final class TemporalConfig extends InjectableConfig
'workers' => [],
];

/**
* @return non-empty-string
*/
public function getDefaultNamespace(): string
{
return $this->config['namespace'];
}

/**
* @return non-empty-string
*/
public function getTemporalNamespace(): string
{
return $this->config['temporalNamespace'];
}

/**
* @return non-empty-string
*/
public function getAddress(): string
{
return $this->config['address'];
}

/**
* @return non-empty-string
*/
public function getDefaultWorker(): string
{
return $this->config['defaultWorker'];
}

/** @psalm-return array<non-empty-string, WorkerOptions> */
/**
* @return array<non-empty-string, WorkerOptions|TWorker>
*/
public function getWorkers(): array
{
return (array) $this->config['workers'];
return $this->config['workers'] ?? [];
}
}
Loading

0 comments on commit c555447

Please sign in to comment.