diff --git a/composer.json b/composer.json index 8c74448..9f3df76 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Micro Framework: TemporalIO plugin", "type": "library", "license": "MIT", - "version": "0.1", + "version": "1.0", "autoload": { "psr-4": { "Micro\\Plugin\\Temporal\\": "src/" @@ -15,15 +15,13 @@ "email": "stanislau_komar@epam.com" } ], - "scripts": { - "phpcs": "phpcs -p ./src --standard=vendor/phpcompatibility/php-compatibility/PHPCompatibility --runtime-set testVersion 8.0" - }, "require": { + "micro/kernel": "^1", "temporal/sdk": ">=2.0", "spiral/tokenizer": ">=2.7" }, "require-dev": { - "squizlabs/php_codesniffer": "^3.7", - "phpcompatibility/php-compatibility": "^9.3" + }, + "scripts": { } } diff --git a/src/Activity/Builder/ActivityStubBuilderInterface.php b/src/Activity/Builder/ActivityStubBuilderInterface.php deleted file mode 100644 index 11dd671..0000000 --- a/src/Activity/Builder/ActivityStubBuilderInterface.php +++ /dev/null @@ -1,7 +0,0 @@ - $activityInterface + * + * @return T + */ + public function create(string $activityInterface): ActivityProxy; +} \ No newline at end of file diff --git a/src/Configuration/Client/WorkflowClientConfiguration.php b/src/Configuration/Client/WorkflowClientConfiguration.php index a4c740a..2983714 100644 --- a/src/Configuration/Client/WorkflowClientConfiguration.php +++ b/src/Configuration/Client/WorkflowClientConfiguration.php @@ -4,7 +4,8 @@ use Micro\Framework\Kernel\Configuration\PluginRoutingKeyConfiguration; -class WorkflowClientConfiguration extends PluginRoutingKeyConfiguration implements WorkflowClientConfigurationInterface +class +WorkflowClientConfiguration extends PluginRoutingKeyConfiguration implements WorkflowClientConfigurationInterface { const CFG_TEMPORAL_HOST = 'TEMPORAL_CLIENT_%s_HOST'; const CFG_TEMPORAL_PORT = 'TEMPORAL_CLIENT_%s_PORT'; diff --git a/src/Configuration/RoadRunner/RoadRunnerConfiguration.php b/src/Configuration/RoadRunner/RoadRunnerConfiguration.php index 05b1888..9af48ab 100644 --- a/src/Configuration/RoadRunner/RoadRunnerConfiguration.php +++ b/src/Configuration/RoadRunner/RoadRunnerConfiguration.php @@ -17,7 +17,7 @@ class RoadRunnerConfiguration extends PluginRoutingKeyConfiguration implements R */ public function getRelayAddress(): string { - return $this->get(self::CFG_RELAY_ADDRESS, 'tcp://127.0.0.1:7233'); + return $this->get(self::CFG_RELAY_ADDRESS, 'tcp://localhost:7233'); } /** @@ -25,7 +25,7 @@ public function getRelayAddress(): string */ public function getRPCAddress(): string { - return $this->get(self::CFG_RPC_ADDRESS, 'tcp://127.0.0.1:6001'); + return $this->get(self::CFG_RPC_ADDRESS, 'tcp://localhost:6001'); } #[ExpectedValues(valuesFromClass: Mode::class)] diff --git a/src/Configuration/Worker/WorkflowWorkerConfiguration.php b/src/Configuration/Worker/WorkflowWorkerConfiguration.php index 653f753..30337fe 100644 --- a/src/Configuration/Worker/WorkflowWorkerConfiguration.php +++ b/src/Configuration/Worker/WorkflowWorkerConfiguration.php @@ -23,7 +23,7 @@ class WorkflowWorkerConfiguration extends PluginRoutingKeyConfiguration implemen */ public function getRelayAddress(): string { - return $this->get(self::CFG_RELAY_ADDRESS, 'tcp://127.0.0.1:7233'); + return $this->get(self::CFG_RELAY_ADDRESS, 'tcp://localhost:7233'); } /** @@ -31,7 +31,7 @@ public function getRelayAddress(): string */ public function getRPCAddress(): string { - return $this->get(self::CFG_RPC_ADDRESS, 'tcp://127.0.0.1:6001'); + return $this->get(self::CFG_RPC_ADDRESS, 'tcp://localhost:6001'); } /** diff --git a/src/Facade/TemporalFacade.php b/src/Facade/TemporalFacade.php index dbed61d..3d36efd 100644 --- a/src/Facade/TemporalFacade.php +++ b/src/Facade/TemporalFacade.php @@ -2,12 +2,14 @@ namespace Micro\Plugin\Temporal\Facade; +use Micro\Plugin\Temporal\Activity\Factory\ActivityStubFactoryInterface; use Micro\Plugin\Temporal\Configuration\TemporalPluginConfigurationInterface; use Micro\Plugin\Temporal\Worker\Factory\WorkerFactoryInterface; use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepositoryInterface; use Temporal\Client\WorkflowClientInterface; use Temporal\Client\WorkflowOptions; use Temporal\Internal\Support\Options; +use Temporal\Internal\Workflow\ActivityProxy; use Temporal\Worker\WorkerFactoryInterface as TemporalWorkerFactoryInterface; class TemporalFacade implements TemporalFacadeInterface @@ -15,10 +17,12 @@ class TemporalFacade implements TemporalFacadeInterface /** * @param ClientRepositoryInterface $clientRepository * @param WorkerFactoryInterface $workerFactory + * @param ActivityStubFactoryInterface $activityStubFactory */ public function __construct( private readonly ClientRepositoryInterface $clientRepository, - private readonly WorkerFactoryInterface $workerFactory + private readonly WorkerFactoryInterface $workerFactory, + private readonly ActivityStubFactoryInterface $activityStubFactory ) { } @@ -31,6 +35,14 @@ public function workflowClient(string $clientName = TemporalPluginConfigurationI return $this->clientRepository->client($clientName); } + /** + * {@inheritDoc} + */ + public function createActivityStub(string $activityInterface): ActivityProxy + { + return $this->activityStubFactory->create($activityInterface); + } + /** * {@inheritDoc} */ diff --git a/src/Facade/TemporalFacadeInterface.php b/src/Facade/TemporalFacadeInterface.php index 73e3993..d164b16 100644 --- a/src/Facade/TemporalFacadeInterface.php +++ b/src/Facade/TemporalFacadeInterface.php @@ -5,6 +5,7 @@ use Micro\Plugin\Temporal\Configuration\TemporalPluginConfigurationInterface; use Temporal\Client\WorkflowClientInterface; use Temporal\Internal\Support\Options; +use Temporal\Internal\Workflow\ActivityProxy; use Temporal\Worker\WorkerFactoryInterface as TemporalWorkerFactoryInterface; interface TemporalFacadeInterface @@ -16,6 +17,15 @@ interface TemporalFacadeInterface */ public function workflowClient(string $clientName = TemporalPluginConfigurationInterface::CLIENT_DEFAULT): WorkflowClientInterface; + /** + * @template T + * + * @param class-string $activityInterface + * + * @return T + */ + public function createActivityStub(string $activityInterface): ActivityProxy; + /** * @return Options */ diff --git a/src/TemporalPlugin.php b/src/TemporalPlugin.php index c5e1241..de01ea4 100644 --- a/src/TemporalPlugin.php +++ b/src/TemporalPlugin.php @@ -5,9 +5,13 @@ use Micro\Component\DependencyInjection\Autowire\AutowireHelperFactory; use Micro\Component\DependencyInjection\Autowire\AutowireHelperFactoryInterface; use Micro\Component\DependencyInjection\Container; -use Micro\Framework\Kernel\Plugin\AbstractPlugin; +use Micro\Framework\Kernel\Plugin\ConfigurableInterface; +use Micro\Framework\Kernel\Plugin\DependencyProviderInterface; +use Micro\Framework\Kernel\Plugin\PluginConfigurationTrait; use Micro\Library\DTO\SerializerFacadeInterface; use Micro\Plugin\Locator\Facade\LocatorFacadeInterface; +use Micro\Plugin\Temporal\Activity\Factory\ActivityStubFactory; +use Micro\Plugin\Temporal\Activity\Factory\ActivityStubFactoryInterface; use Micro\Plugin\Temporal\Configuration\TemporalPluginConfigurationInterface; use Micro\Plugin\Temporal\Facade\TemporalFacade; use Micro\Plugin\Temporal\Facade\TemporalFacadeInterface; @@ -19,17 +23,19 @@ use Micro\Plugin\Temporal\Worker\Factory\WorkerFactoryInterface; use Micro\Plugin\Temporal\Workflow\Client\Factory\ClientFactory; use Micro\Plugin\Temporal\Workflow\Client\Factory\ClientFactoryInterface; -use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepository; use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepositoryFactory; use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepositoryFactoryInterface; +use Micro\Plugin\Temporal\Workflow\Client\Repository\ClientRepositoryInterface; use Micro\Plugin\Temporal\Workflow\DataConverter\DataConverterFactory; use Micro\Plugin\Temporal\Workflow\DataConverter\DataConverterFactoryInterface; /** * @method TemporalPluginConfigurationInterface configuration() */ -class TemporalPlugin extends AbstractPlugin +class TemporalPlugin implements DependencyProviderInterface, ConfigurableInterface { + use PluginConfigurationTrait; + /** * @var SerializerFacadeInterface|null */ @@ -69,7 +75,8 @@ protected function createFacade(): TemporalFacadeInterface { return new TemporalFacade( clientRepository: $this->createWorkflowClientRepository(), - workerFactory: $this->createWorkerFactory() + workerFactory: $this->createWorkerFactory(), + activityStubFactory: $this->createActivityStubFactory() ); } @@ -101,9 +108,9 @@ protected function createWorkflowClientRepositoryFactory(): ClientRepositoryFact } /** - * @return ClientRepository + * @return ClientRepositoryInterface */ - protected function createWorkflowClientRepository(): ClientRepository + protected function createWorkflowClientRepository(): ClientRepositoryInterface { return $this->createWorkflowClientRepositoryFactory()->create(); } @@ -116,6 +123,17 @@ protected function createWorkerExpanderFactory(): WorkerExpanderFactoryInterface ); } + /** + * @return ActivityStubFactoryInterface + */ + protected function createActivityStubFactory(): ActivityStubFactoryInterface + { + return new ActivityStubFactory(); + } + + /** + * @return WorkerFactoryInterface + */ protected function createWorkerFactory(): WorkerFactoryInterface { return new WorkerFactory( diff --git a/src/Worker/Expander/WorkerExpander.php b/src/Worker/Expander/WorkerExpander.php index a7f2d3a..9d7fa8f 100644 --- a/src/Worker/Expander/WorkerExpander.php +++ b/src/Worker/Expander/WorkerExpander.php @@ -5,7 +5,6 @@ use Micro\Component\DependencyInjection\Autowire\AutowireHelperFactoryInterface; use Micro\Plugin\Locator\Facade\LocatorFacadeInterface; use Micro\Plugin\Temporal\Activity\ActivityInterface; -use Micro\Plugin\Temporal\Activity\Locator\ActivityLocatorInterface; use Micro\Plugin\Temporal\Workflow\WorkflowInterface; use Temporal\Worker\WorkerInterface; diff --git a/src/Worker/Factory/WorkerFactory.php b/src/Worker/Factory/WorkerFactory.php index 82bdca2..1b0f2d9 100644 --- a/src/Worker/Factory/WorkerFactory.php +++ b/src/Worker/Factory/WorkerFactory.php @@ -40,7 +40,7 @@ public function create(string $workerName): TemporalWorkerFactoryInterface $worker = $workerFactory->newWorker( $configuration->getQueueName(), - WorkerOptions::new() + WorkerOptions::new(), ); $this->workerExpanderFactory->create()->expand($worker); diff --git a/src/Workflow/DataConverter/DataConverterFactory.php b/src/Workflow/DataConverter/DataConverterFactory.php index 3cae77a..4a41cb7 100644 --- a/src/Workflow/DataConverter/DataConverterFactory.php +++ b/src/Workflow/DataConverter/DataConverterFactory.php @@ -28,10 +28,10 @@ public function create(): DataConverterInterface { return new DataConverter( new DtoPayloadDataConverter($this->serializerFacade), + new JsonConverter(), new NullConverter(), new BinaryConverter(), new ProtoJsonConverter(), - new JsonConverter() ); } } \ No newline at end of file