HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/ai.naniguide.com/app/Jobs/CacheAttachments.php
<?php

namespace App\Jobs;

use Illuminate\Queue\Middleware\WithoutOverlapping;
use Illuminate\Contracts\Queue\ShouldBeUnique;

class CacheAttachments extends Base implements ShouldBeUnique
{
    public $uniqueFor = 3600; // seconds

    // @important: this job only works in Master Server
    public $timeout = 7200;

    protected $campaign;

    /**
     * Create a new job instance.
     */
    public function __construct($campaign)
    {
        $this->campaign = $campaign;
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        if (config('custom.distributed_mode')) {
            if (!config('custom.distributed_master')) {
                $msg = 'CacheAttachments job must be executed on a Master server only (with DISTRIBUTED_MASTER=true in .env)';
                $this->campaign->setFailed($msg);
                throw new \Exception($msg);
            }
        }

        foreach ($this->campaign->attachments as $a) {
            $a->cacheToRedis();
        }
    }

    public function uniqueId(): string
    {
        return $this->campaign->uid;
    }
}