HEX
Server: Apache
System: Linux efa57bbe-abb1-400d-2985-3b056fbc2701.secureserver.net 6.1.147-1.el9.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jul 24 12:33:32 EDT 2025 x86_64
User: root (0)
PHP: 8.0.30.4
Disabled: NONE
Upload Files
File: /var/www/wp-content/mu-plugins/vendor/godaddy/mwc-core/src/JobQueue/Traits/QueueableJobTrait.php
<?php

namespace GoDaddy\WordPress\MWC\Core\JobQueue\Traits;

use GoDaddy\WordPress\MWC\Common\Events\Events;
use GoDaddy\WordPress\MWC\Core\JobQueue\Contracts\QueueableJobContract;
use GoDaddy\WordPress\MWC\Core\JobQueue\Events\QueuedJobDoneEvent;

/**
 * Trait for queueable jobs, to implement common methods in the {@see QueueableJobContract} interface.
 */
trait QueueableJobTrait
{
    /** @var class-string<QueueableJobContract>[] chain of job class names, in the order they should be run */
    protected array $chain;

    /** @var ?mixed[] optional arguments for the current job; these values may change per job run (example: an offset for a query, a batch of IDs to process, etc.) */
    protected ?array $args = null;

    /**
     * Add an array of jobs (class names) to the queue.
     *
     * @param class-string<QueueableJobContract>[] $chain
     * @return $this
     */
    public function setChain(array $chain)
    {
        $this->chain = $chain;

        return $this;
    }

    /**
     * @param ?array<mixed> $args
     * @return $this
     */
    public function setArgs(?array $args = null)
    {
        $this->args = $args;

        return $this;
    }

    /**
     * Sets the chain to the current job class.
     *
     * This is useful for things like batch jobs where an array of items is passed in, and the job needs to be re-queued
     * until all the items in the array have been processed.
     *
     * @return $this
     */
    public function reQueueJob()
    {
        array_unshift($this->chain, get_class($this));

        return $this;
    }

    /**
     * Job processed successfully.
     *
     * @return void
     */
    public function jobDone() : void
    {
        Events::broadcast(QueuedJobDoneEvent::getNewInstance($this->chain, $this->args));
    }

    /**
     * {@inheritDoc}
     */
    public function getJobKey() : string
    {
        return static::JOB_KEY;
    }
}