Skip to content

Commit

Permalink
Merge pull request #1 from Micro-PHP/v1.0
Browse files Browse the repository at this point in the history
v1.0
  • Loading branch information
Asisyas authored Dec 25, 2022
2 parents b06f385 + 6a30dce commit 34342fc
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 28 deletions.
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand All @@ -15,15 +15,13 @@
"email": "[email protected]"
}
],
"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": {
}
}
7 changes: 0 additions & 7 deletions src/Activity/Builder/ActivityStubBuilderInterface.php

This file was deleted.

20 changes: 20 additions & 0 deletions src/Activity/Factory/ActivityStubFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Micro\Plugin\Temporal\Activity\Factory;

use Temporal\Activity\ActivityOptions;
use Temporal\Internal\Workflow\ActivityProxy;
use Temporal\Workflow;

class ActivityStubFactory implements ActivityStubFactoryInterface
{
/**
* {@inheritDoc}
*/
public function create(string $activityInterface): ActivityProxy
{
return Workflow::newActivityStub($activityInterface,
ActivityOptions::new()
);
}
}
17 changes: 17 additions & 0 deletions src/Activity/Factory/ActivityStubFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Micro\Plugin\Temporal\Activity\Factory;

use Temporal\Internal\Workflow\ActivityProxy;

interface ActivityStubFactoryInterface
{
/**
* @template T
*
* @param class-string<T> $activityInterface
*
* @return T
*/
public function create(string $activityInterface): ActivityProxy;
}
3 changes: 2 additions & 1 deletion src/Configuration/Client/WorkflowClientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/RoadRunner/RoadRunnerConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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');
}

/**
* {@inheritDoc}
*/
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)]
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration/Worker/WorkflowWorkerConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ 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');
}

/**
* {@inheritDoc}
*/
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');
}

/**
Expand Down
14 changes: 13 additions & 1 deletion src/Facade/TemporalFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

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
{
/**
* @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
)
{
}
Expand All @@ -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}
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Facade/TemporalFacadeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,6 +17,15 @@ interface TemporalFacadeInterface
*/
public function workflowClient(string $clientName = TemporalPluginConfigurationInterface::CLIENT_DEFAULT): WorkflowClientInterface;

/**
* @template T
*
* @param class-string<T> $activityInterface
*
* @return T
*/
public function createActivityStub(string $activityInterface): ActivityProxy;

/**
* @return Options
*/
Expand Down
30 changes: 24 additions & 6 deletions src/TemporalPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -69,7 +75,8 @@ protected function createFacade(): TemporalFacadeInterface
{
return new TemporalFacade(
clientRepository: $this->createWorkflowClientRepository(),
workerFactory: $this->createWorkerFactory()
workerFactory: $this->createWorkerFactory(),
activityStubFactory: $this->createActivityStubFactory()
);
}

Expand Down Expand Up @@ -101,9 +108,9 @@ protected function createWorkflowClientRepositoryFactory(): ClientRepositoryFact
}

/**
* @return ClientRepository
* @return ClientRepositoryInterface
*/
protected function createWorkflowClientRepository(): ClientRepository
protected function createWorkflowClientRepository(): ClientRepositoryInterface
{
return $this->createWorkflowClientRepositoryFactory()->create();
}
Expand All @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/Worker/Expander/WorkerExpander.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/Worker/Factory/WorkerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function create(string $workerName): TemporalWorkerFactoryInterface

$worker = $workerFactory->newWorker(
$configuration->getQueueName(),
WorkerOptions::new()
WorkerOptions::new(),
);

$this->workerExpanderFactory->create()->expand($worker);
Expand Down
2 changes: 1 addition & 1 deletion src/Workflow/DataConverter/DataConverterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}

0 comments on commit 34342fc

Please sign in to comment.