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

namespace App\Jobs;

use Exception;

class ForceTriggerAutomationViaApi extends Base
{
    protected $automation;
    protected $customer;

    public $timeout = 7200;

    public function __construct($automation)
    {
        $this->automation = $automation;
        $this->customer = $this->automation->customer;

        if (!$this->automation->allowApiCall()) {
            throw new Exception(sprintf('Automation "%s" is not set up to be triggered via API. Cannot start!', $this->automation->name));
        }
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $this->customer->setUserDbConnection();

        if (!$this->automation->allowApiCall()) {
            $this->automation->logger()->info(sprintf('Automation "%s" is not set up to be triggered via API (job handle)', $this->automation->name));
            throw new Exception("Automation is not set up to be triggered via API (job handle)");
        }
        $this->automation->logger()->info(sprintf('Actually run automation "%s" in response to API call', $this->automation->name));
        $this->automation->forceTrigger();
    }
}