Files
citrus-cms/app/Jobs/ExecuteMaterialGroupUpdaterJob.php
2026-04-28 21:14:25 +03:00

92 lines
2.3 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 ExecuteMaterialGroupUpdaterJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* The number of seconds the job can run before timing out.
*/
public $timeout = 300;
/**
* The number of times the job may be attempted.
*/
public $tries = 1;
public $maxExceptions = 1;
protected $weldLogId;
/**
* Create a new job instance.
*
* @param int $weldLogId Weld log record ID
*/
public function __construct(int $weldLogId)
{
$this->weldLogId = $weldLogId;
$this->onQueue('save-trigger');
}
/**
* Execute the job.
*/
public function handle(): void
{
Log::info("=== ExecuteMaterialGroupUpdaterJob STARTED ===", [
'weld_log_id' => $this->weldLogId,
'timestamp' => now(),
]);
try {
if (function_exists('materialGroupUpdater')) {
$result = materialGroupUpdater($this->weldLogId);
Log::info("ExecuteMaterialGroupUpdaterJob completed", [
'weld_log_id' => $this->weldLogId,
'result' => $result,
]);
} else {
Log::warning("materialGroupUpdater function not found", [
'weld_log_id' => $this->weldLogId,
]);
}
} catch (\Throwable $th) {
Log::error("ExecuteMaterialGroupUpdaterJob failed", [
'weld_log_id' => $this->weldLogId,
'error' => $th->getMessage(),
'trace' => $th->getTraceAsString()
]);
throw $th;
}
Log::info("=== ExecuteMaterialGroupUpdaterJob COMPLETED ===", [
'weld_log_id' => $this->weldLogId,
'timestamp' => now(),
]);
}
/**
* Get the tags that should be assigned to the job.
*/
public function tags(): array
{
return [
"MaterialGroupUpdater",
"WeldLog:{$this->weldLogId}",
];
}
}