Repository navigation
Octane aware batch column from docs #1456
|
Greetings all. How to properly implement the example from docs to be compatible with octane ? |
Replies: 1 comment
|
The part to change is where the UUID is generated. In the documentation example, it is created in the service provider's Use a scoped container binding and resolve it inside the callback: namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Spatie\Activitylog\Contracts\Activity as ActivityContract;
use Spatie\Activitylog\Facades\Activity;
class AppServiceProvider extends ServiceProvider
{
public function register(): void
{
$this->app->scoped(
'activity.request_batch_uuid',
static fn () => (string) Str::uuid(),
);
}
public function boot(): void
{
Activity::beforeLogging(
static function (ActivityContract $activity): void {
$activity->batch_uuid =
app('activity.request_batch_uuid');
}
);
}
}Keep the All activities logged within one request will resolve the same UUID. Laravel flushes scoped instances when Octane starts the next request, so its first activity will generate a new UUID. The same lifecycle separation applies to Laravel queue jobs. Importantly, do not resolve the binding in To verify, log two activities in request A and two in request B through Octane. The two rows within each request should share a UUID, while A and B should have different UUIDs. This groups activities per request/job. If you need one business operation to span several jobs, pass an explicit operation identifier instead. References: |
The part to change is where the UUID is generated. In the documentation example, it is created in the service provider's
boot()method and captured by the callback. Under Octane, that can reuse the same UUID across multiple requests handled by the worker.Use a scoped container binding and resolve it inside the callback: