Skip to content

v1.3.0

Choose a tag to compare

@butschster butschster released this 18 Jul 10:06
· 18 commits to master since this release
1294cf6

What's Changed

  • Adding an ability to register activities and workflows in specific workers by @msmakouz in #20
// file app/config/temporal.php

use Temporal\Worker\WorkerOptions;

return [
    'workers' => [
        'worker1' => WorkerOptions::new()
    ]
]

or

<?php

declare(strict_types=1);

namespace App\Bootloader;

use Spiral\Boot\Bootloader\Bootloader;
use Spiral\TemporalBridge\Bootloader\TemporalBridgeBootloader;
use Temporal\Worker\WorkerOptions;

final class AppBootloader extends Bootloader
{
    public function boot(TemporalBridgeBootloader $temporalBridgeBootloader): void 
    {
        $temporalBridgeBootloader->addWorkerOptions('worker1', WorkerOptions::new());
        $temporalBridgeBootloader->addWorkerOptions('worker2', WorkerOptions::new());
    }
}

or

<?php

declare(strict_types=1);

namespace App\Bootloader;

use Spiral\Bootloader\DomainBootloader;
use Spiral\TemporalBridge\WorkersRegistryInterface;use Temporal\Worker\WorkerOptions;

class AppBootloader extends DomainBootloader
{
    public function boot(WorkersRegistryInterface $workersRegistry): void
    {
        $workersRegistry->register(
            'worker1', 
            WorkerOptions::new()->...
        );
    }
}

Workflow example:

<?php

declare(strict_types=1);

namespace App\Workflow;

use Spiral\TemporalBridge\Attribute\AssignWorker;
use Temporal\Workflow\WorkflowInterface;

#[AssignWorker(name: 'worker1')]
#[WorkflowInterface]
interface MoneyTransferWorkflowInterface
{
    #[WorkflowMethod]
    public function transfer(...): \Generator;

    #[SignalMethod]
    function withdraw(): void;

    #[SignalMethod]
    function deposit(): void;
}

Activity example:

<?php

declare(strict_types=1);

namespace App\Workflow;

use Spiral\TemporalBridge\Attribute\AssignWorker;
use Temporal\Activity\ActivityInterface;
use Temporal\Activity\ActivityMethod;

#[AssignWorker(name: 'worker1')]
#[ActivityInterface(...)]
interface MoneyTransferActivityInterface
{
    #[ActivityMethod]
    public function transfer(...): int;

    #[ActivityMethod]
    public function cancel(...): bool;
}

Full Changelog: 1.2.0...1.3.0