İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
<?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 SyncTriggerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* The number of seconds the job can run before timing out.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $timeout = 600; // 10 minutes
|
||||
|
||||
/**
|
||||
* The number of times the job may be attempted.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $tries = 2;
|
||||
|
||||
protected $syncPath;
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param string $syncPath The blade view path to render
|
||||
* @param mixed $id The record ID to pass to the view
|
||||
*/
|
||||
public function __construct(string $syncPath, $id)
|
||||
{
|
||||
$this->syncPath = $syncPath;
|
||||
$this->id = $id;
|
||||
|
||||
// Use the 'save-trigger' queue or a dedicated 'sync' queue
|
||||
$this->onQueue('save-trigger');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
Log::info("=== SyncTriggerJob STARTED ===", [
|
||||
'sync_path' => $this->syncPath,
|
||||
'id' => $this->id,
|
||||
'timestamp' => now()
|
||||
]);
|
||||
|
||||
try {
|
||||
// Render the view to trigger its internal logic
|
||||
// We use render() which will execute the PHP code inside the Blade file
|
||||
$output = view($this->syncPath, ['id' => $this->id])->render();
|
||||
|
||||
Log::info("=== SyncTriggerJob COMPLETED ===", [
|
||||
'sync_path' => $this->syncPath,
|
||||
'id' => $this->id,
|
||||
'timestamp' => now()
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
Log::error("SyncTriggerJob FAILED", [
|
||||
'sync_path' => $this->syncPath,
|
||||
'id' => $this->id,
|
||||
'error' => $e->getMessage(),
|
||||
'trace' => $e->getTraceAsString()
|
||||
]);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the job's description for Telescope.
|
||||
*/
|
||||
public function getDescription(): string
|
||||
{
|
||||
return "Sync Trigger: {$this->syncPath} for ID {$this->id}";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tags that should be assigned to the job.
|
||||
*/
|
||||
public function tags(): array
|
||||
{
|
||||
return [
|
||||
"SyncTrigger",
|
||||
"View:{$this->syncPath}",
|
||||
"ID:{$this->id}"
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user