Update
This commit is contained in:
69
app/Jobs/TrackContentSelectionJob.php
Normal file
69
app/Jobs/TrackContentSelectionJob.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\TrackingContentSelection;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TrackContentSelectionJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
private string $deviceId,
|
||||
private string $contentType,
|
||||
private int $contentId,
|
||||
private string $contentName,
|
||||
private string $selectionMethod,
|
||||
private ?string $searchQuery,
|
||||
private Carbon $actionAt,
|
||||
private ?string $userAgent,
|
||||
private ?string $ipAddress,
|
||||
private string $platform
|
||||
) {
|
||||
$this->onQueue('tracking');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
TrackingContentSelection::create([
|
||||
'device_id' => $this->deviceId,
|
||||
'content_type' => $this->contentType,
|
||||
'content_id' => $this->contentId,
|
||||
'content_name' => $this->contentName,
|
||||
'selection_method' => $this->selectionMethod,
|
||||
'search_query' => $this->searchQuery,
|
||||
'action_at' => $this->actionAt,
|
||||
'user_agent' => $this->userAgent,
|
||||
'ip_address' => $this->ipAddress,
|
||||
'platform' => $this->platform,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to track content selection', [
|
||||
'device_id' => $this->deviceId,
|
||||
'content_type' => $this->contentType,
|
||||
'content_id' => $this->contentId,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function failed(\Throwable $exception): void
|
||||
{
|
||||
Log::error('TrackContentSelectionJob failed permanently', [
|
||||
'device_id' => $this->deviceId,
|
||||
'content_type' => $this->contentType,
|
||||
'content_id' => $this->contentId,
|
||||
'exception' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
74
app/Jobs/TrackExportJob.php
Normal file
74
app/Jobs/TrackExportJob.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\TrackingExport;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TrackExportJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
private string $deviceId,
|
||||
private ?int $memeId,
|
||||
private ?int $memeMediaId,
|
||||
private ?int $backgroundMediaId,
|
||||
private array $captionTexts,
|
||||
private string $exportFormat,
|
||||
private string $exportQuality,
|
||||
private Carbon $actionAt,
|
||||
private ?string $userAgent,
|
||||
private ?string $ipAddress,
|
||||
private string $platform
|
||||
) {
|
||||
$this->onQueue('tracking');
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
try {
|
||||
$trackingExport = TrackingExport::create([
|
||||
'device_id' => $this->deviceId,
|
||||
'meme_id' => $this->memeId,
|
||||
'meme_media_id' => $this->memeMediaId,
|
||||
'background_media_id' => $this->backgroundMediaId,
|
||||
'caption_texts' => $this->captionTexts,
|
||||
'export_format' => $this->exportFormat,
|
||||
'export_quality' => $this->exportQuality,
|
||||
'export_status' => 'initiated',
|
||||
'action_at' => $this->actionAt,
|
||||
'user_agent' => $this->userAgent,
|
||||
'ip_address' => $this->ipAddress,
|
||||
'platform' => $this->platform,
|
||||
]);
|
||||
|
||||
return $trackingExport->id;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to track export', [
|
||||
'device_id' => $this->deviceId,
|
||||
'meme_id' => $this->memeId,
|
||||
'export_format' => $this->exportFormat,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function failed(\Throwable $exception): void
|
||||
{
|
||||
Log::error('TrackExportJob failed permanently', [
|
||||
'device_id' => $this->deviceId,
|
||||
'meme_id' => $this->memeId,
|
||||
'export_format' => $this->exportFormat,
|
||||
'exception' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
65
app/Jobs/TrackSearchJob.php
Normal file
65
app/Jobs/TrackSearchJob.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\TrackingSearch;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TrackSearchJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
private string $deviceId,
|
||||
private string $searchType,
|
||||
private string $searchQuery,
|
||||
private ?array $searchFilters,
|
||||
private Carbon $actionAt,
|
||||
private ?string $userAgent,
|
||||
private ?string $ipAddress,
|
||||
private string $platform
|
||||
) {
|
||||
$this->onQueue('tracking');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
TrackingSearch::create([
|
||||
'device_id' => $this->deviceId,
|
||||
'search_type' => $this->searchType,
|
||||
'search_query' => $this->searchQuery,
|
||||
'search_filters' => $this->searchFilters,
|
||||
'action_at' => $this->actionAt,
|
||||
'user_agent' => $this->userAgent,
|
||||
'ip_address' => $this->ipAddress,
|
||||
'platform' => $this->platform,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to track search', [
|
||||
'device_id' => $this->deviceId,
|
||||
'search_type' => $this->searchType,
|
||||
'search_query' => $this->searchQuery,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function failed(\Throwable $exception): void
|
||||
{
|
||||
Log::error('TrackSearchJob failed permanently', [
|
||||
'device_id' => $this->deviceId,
|
||||
'search_type' => $this->searchType,
|
||||
'search_query' => $this->searchQuery,
|
||||
'exception' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
66
app/Jobs/UpdateExportStatusJob.php
Normal file
66
app/Jobs/UpdateExportStatusJob.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\TrackingExport;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateExportStatusJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
private int $trackingExportId,
|
||||
private string $status,
|
||||
private ?string $errorMessage,
|
||||
private ?Carbon $completedAt
|
||||
) {
|
||||
$this->onQueue('tracking');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
try {
|
||||
$trackingExport = TrackingExport::findOrFail($this->trackingExportId);
|
||||
|
||||
$updateData = [
|
||||
'export_status' => $this->status,
|
||||
];
|
||||
|
||||
if ($this->errorMessage !== null) {
|
||||
$updateData['error_message'] = $this->errorMessage;
|
||||
}
|
||||
|
||||
if ($this->completedAt !== null) {
|
||||
$updateData['completed_at'] = $this->completedAt;
|
||||
} elseif (in_array($this->status, ['completed', 'failed'])) {
|
||||
$updateData['completed_at'] = now();
|
||||
}
|
||||
|
||||
$trackingExport->update($updateData);
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to update export status', [
|
||||
'tracking_export_id' => $this->trackingExportId,
|
||||
'status' => $this->status,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function failed(\Throwable $exception): void
|
||||
{
|
||||
Log::error('UpdateExportStatusJob failed permanently', [
|
||||
'tracking_export_id' => $this->trackingExportId,
|
||||
'status' => $this->status,
|
||||
'exception' => $exception->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user