-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat(#20): Introduce support for tracking requests via a queued job BREAKING CHANGE: Changes to the API to support tracking requests via a queued job * refactor(#20): Only support PHP 8.0 for this version * refactor(#20): Update ubuntu version and node version
- Loading branch information
Showing
16 changed files
with
241 additions
and
294 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
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
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
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
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,9 @@ | ||
<?php | ||
|
||
namespace OhSeeSoftware\LaravelServerAnalytics\Exceptions; | ||
|
||
use Exception; | ||
|
||
class MissingMetaKeyException extends Exception | ||
{ | ||
} |
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
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
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,55 @@ | ||
<?php | ||
|
||
namespace OhSeeSoftware\LaravelServerAnalytics\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Support\Carbon; | ||
use OhSeeSoftware\LaravelServerAnalytics\Exceptions\MissingMetaKeyException; | ||
use OhSeeSoftware\LaravelServerAnalytics\Facades\ServerAnalytics; | ||
use OhSeeSoftware\LaravelServerAnalytics\Models\Analytics; | ||
use OhSeeSoftware\LaravelServerAnalytics\RequestDetails; | ||
|
||
class LogRequestRecord implements ShouldQueue | ||
{ | ||
use Dispatchable; | ||
use InteractsWithQueue; | ||
use Queueable; | ||
use SerializesModels; | ||
|
||
public $tries = 5; | ||
|
||
public $backoff = 10; | ||
|
||
public function __construct(public array $requestData) | ||
{ | ||
} | ||
|
||
public function handle() | ||
{ | ||
$analytics = Analytics::create($this->requestData); | ||
|
||
collect($this->requestData['meta'] ?? []) | ||
->each(function ($meta) use ($analytics) { | ||
$key = $meta['key'] ?? null; | ||
if (!$key) { | ||
throw new MissingMetaKeyException('Missing meta `key`!'); | ||
} | ||
$analytics->addMeta($key, $meta['value'] ?? null); | ||
}); | ||
|
||
collect($this->requestData['relations'] ?? []) | ||
->each(function ($relation) use ($analytics) { | ||
$model = $relation['model'] ?? null; | ||
if (!$model) { | ||
throw new MissingMetaKeyException('Missing relation `model`!'); | ||
} | ||
$analytics->addRelation($model, $relation['reason'] ?? null); | ||
}); | ||
} | ||
} |
Oops, something went wrong.