-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EasyBugsnag] Session tracking for laravel queue job (#655)
- Loading branch information
Showing
3 changed files
with
60 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/EasyBugsnag/src/Bridge/Laravel/Session/SessionTrackingQueueListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EonX\EasyBugsnag\Bridge\Laravel\Session; | ||
|
||
use Bugsnag\Client; | ||
use Illuminate\Queue\Events\JobProcessing; | ||
|
||
final class SessionTrackingQueueListener | ||
{ | ||
/** | ||
* @var \Bugsnag\Client | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $configured = false; | ||
|
||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
public function handle(JobProcessing $event): void | ||
{ | ||
$sessionTracker = $this->client->getSessionTracker(); | ||
$sessionTracker->startSession(); | ||
|
||
if ($this->configured) { | ||
return; | ||
} | ||
|
||
// Make sure sessions are sent when worker stops | ||
\register_shutdown_function(static function () use ($sessionTracker): void { | ||
$sessionTracker->sendSessions(); | ||
}); | ||
|
||
$this->configured = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters