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/VerifyMailListJob.php
<?php

namespace App\Jobs;

use App\Model\EmailVerificationServer;
use App\Model\MailList;
use Exception;
use App\Library\Traits\Trackable;
use Illuminate\Bus\Batchable;

class VerifyMailListJob extends Base
{
    use Batchable;
    use Trackable;

    public $timeout = 14400;

    protected $mailList;
    protected $server;
    protected $subscription;
    protected $customer;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($mailList, EmailVerificationServer $server, $subscription)
    {
        $this->mailList = $mailList;
        $this->server = $server;
        $this->subscription = $subscription;

        $this->customer = $this->mailList->customer;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        if ($this->batch()->cancelled()) {
            return;
        }

        $this->customer->setUserDbConnection();

        $this->monitor->setJsonData([
            'percentage' => 0,
            'total' => 0,
            'processed' => 0,
            'failed' => 0,
            'message' => 'Verification is in progress...',
        ]);

        // Get subscribers that are not verified
        $query = $this->mailList->subscribers()->unverified();

        if (!$query->exists()) {
            throw new Exception('There is no unverified contact in your list');
        }

        $this->monitor->updateJsonData([
            'message' => "Verification is in progress ({$query->count()})...",
        ]);

        // Query batches of 1000 records each, dispatch the verification job
        // Add job to batch
        cursorIterate($query, 'subscribers.id', $size = 1000, function ($subscribers, $page) {
            foreach ($subscribers as $subscriber) {
                $this->batch()->add(new VerifySubscriber($subscriber, $this->server, $this->subscription));
            }
        });
    }
}