87 lines
2.4 KiB
PHP
87 lines
2.4 KiB
PHP
<?php
|
||
|
||
namespace App\Jobs;
|
||
|
||
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 ExecuteWeldlogSyncJob implements ShouldQueue
|
||
{
|
||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||
|
||
public $timeout = 300;
|
||
public $tries = 1;
|
||
public $maxExceptions = 1;
|
||
|
||
protected $tableName;
|
||
protected $recordId;
|
||
|
||
/**
|
||
* @param string $tableName Log test type table name
|
||
* @param int $recordId Record ID in the table
|
||
*/
|
||
public function __construct(string $tableName, int $recordId)
|
||
{
|
||
$this->tableName = $tableName;
|
||
$this->recordId = $recordId;
|
||
|
||
$this->onQueue('save-trigger');
|
||
}
|
||
|
||
public function handle(): void
|
||
{
|
||
Log::info("=== ExecuteWeldlogSyncJob STARTED ===", [
|
||
'table_name' => $this->tableName,
|
||
'record_id' => $this->recordId,
|
||
]);
|
||
|
||
try {
|
||
// Kayıt verisini kuyruk içinde çek (response'u yavaşlatmaz)
|
||
$recordData = db($this->tableName)->where('id', $this->recordId)->first();
|
||
|
||
if (!$recordData) {
|
||
Log::warning("ExecuteWeldlogSyncJob: Record not found", [
|
||
'table_name' => $this->tableName,
|
||
'record_id' => $this->recordId,
|
||
]);
|
||
return;
|
||
}
|
||
|
||
$data = (array) $recordData;
|
||
|
||
if (function_exists('logToWeldlogUpdate')) {
|
||
logToWeldlogUpdate($data);
|
||
}
|
||
|
||
if (function_exists('logToWPQUpdate')) {
|
||
logToWPQUpdate($data, $this->tableName);
|
||
}
|
||
|
||
} catch (\Throwable $th) {
|
||
Log::error("ExecuteWeldlogSyncJob failed", [
|
||
'table_name' => $this->tableName,
|
||
'record_id' => $this->recordId,
|
||
'error' => $th->getMessage(),
|
||
]);
|
||
throw $th;
|
||
}
|
||
|
||
Log::info("=== ExecuteWeldlogSyncJob COMPLETED ===", [
|
||
'table_name' => $this->tableName,
|
||
'record_id' => $this->recordId,
|
||
]);
|
||
}
|
||
|
||
public function tags(): array
|
||
{
|
||
return [
|
||
"WeldlogSync:{$this->tableName}",
|
||
"RecordId:{$this->recordId}",
|
||
];
|
||
}
|
||
}
|