Skip to content

Keep long-lived workers safe

Workflow services keep dependencies in constructors and accept actor or tenant data through execute() or a scoped context. The reference app simulates Laravel’s scoped reset; it does not prove an Octane deployment or tenant security.

Before you begin

Run composer run reference:test:lifecycle and read Octane safety.

Bind context to the scoped lifetime

examples/reference-app/app/Pulsar/Infrastructure/Tenancy/ScopedTenantContext.php — Mutable context that Laravel replaces after a scoped reset.

php
<?php

namespace App\Pulsar\Infrastructure\Tenancy;

use App\Pulsar\Domain\Orders\Contracts\TenantContext;

final class ScopedTenantContext implements TenantContext
{
    private string $tenantId = '';

    // #region scoped-tenant-context
    public function id(): string
    {
        return $this->tenantId;
    }

    public function establish(string $tenantId): void
    {
        $this->tenantId = $tenantId;
    }
    // #endregion
}

Verify and troubleshoot

The lifecycle test calls forgetScopedInstances() and proves a fresh context has no prior tenant. Do not use this simulation as operational evidence for workers, performance, or security controls.