buyanov/symfony-temporal-worker
Installation:
composer require buyanov/symfony-temporal-worker
Ensure your Laravel app uses Symfony’s dependency injection (via symfony/dependency-injection and symfony/http-kernel).
First Use Case:
Define a Temporal Activity (e.g., ProductPropertyActivityInterface) and annotate it with:
#[AutoconfigureTag('temporal.activity')]
#[ActivityInterface('YourNamespace.')] // Unique prefix for activities
Register the worker in config/services.php:
'temporal' => [
'worker' => [
'namespace' => 'App\\Temporal\\Activity',
'task_queue' => 'laravel-queue',
],
],
Run the Worker:
Add a console command (e.g., php artisan temporal:worker) to start the Symfony-based worker:
use Buyanov\TemporalWorker\Worker\Worker;
protected function execute(InputInterface $input, OutputInterface $output): int
{
$worker = new Worker(
$this->getContainer(),
config('temporal.worker.namespace'),
config('temporal.worker.task_queue')
);
$worker->run();
return 0;
}
Activities:
ProductPropertyActivityInterface).@ActivityMethod to define Temporal’s activity names.Workflows:
@AutoconfigureTag('temporal.workflow').#[AutoconfigureTag('temporal.workflow')]
class ProductWorkflow
{
public function __construct(
private ProductPropertyActivityInterface $activity
) {}
public function execute(string $productGuid): string
{
return $this->activity->createOrUpdateProductProperty(
$productGuid,
'property-guid',
'value'
);
}
}
Task Queues:
task_queue in config/temporal.php to match your Temporal server’s queue.#[ActivityMethod('processOrder')]
public function processOrder(string $orderId): void { ... }
ActivityOptions).Workflow::signal() to interrupt workflows (e.g., cancel orders).Namespace Collisions:
Ensure @ActivityInterface prefixes are unique (e.g., App.Temporal.Product.).
Overlapping prefixes cause ActivityNotFoundException.
Worker Registration:
php artisan temporal:worker in a separate process (e.g., Docker, PM2).Dependency Injection:
#[Autowire]).Debugging:
http://localhost:8080) for workflow runs.Temporal\Activity\ActivityOptions::setLogger().Configuration:
Extend config/temporal.php for custom options:
'worker' => [
'poll_interval' => 1000, // Milliseconds
'max_concurrent_activities' => 10,
],
Testing:
Use Temporal’s TestWorkflowEnvironment for unit tests:
$env = new TestWorkflowEnvironment();
$result = $env->executeWorkflow(new ProductWorkflow(), ['orderId']);
Laravel Integration:
WorkflowId in Laravel’s database for tracking.OrderCreated event).Performance:
max_concurrent_activities to avoid throttling.How can I help you explore Laravel packages today?