master

laravel/framework

Last updated at: 29/12/2023 09:24

SyncJob.php

TLDR

The provided file, SyncJob.php, is a class that extends the Job class and implements the JobContract interface. It represents a synchronous job in the Illuminate Queue system.

Methods

__construct

This method is the constructor of the SyncJob class. It initializes the properties of the class with the provided arguments.

release

This method is used to release the job back into the queue after a specified delay. It calls the release method of the parent Job class.

attempts

This method returns the number of times the job has been attempted. In this case, it always returns 1.

getJobId

This method returns the job identifier. In this case, it always returns an empty string.

getRawBody

This method returns the raw body string for the job. It simply returns the payload property.

getQueue

This method returns the name of the queue the job belongs to. In this case, it always returns 'sync'.

Classes

There are no additional classes in the file.

<?php

namespace Illuminate\Queue\Jobs;

use Illuminate\Container\Container;
use Illuminate\Contracts\Queue\Job as JobContract;

class SyncJob extends Job implements JobContract
{
    /**
     * The class name of the job.
     *
     * @var string
     */
    protected $job;

    /**
     * The queue message data.
     *
     * @var string
     */
    protected $payload;

    /**
     * Create a new job instance.
     *
     * @param  \Illuminate\Container\Container  $container
     * @param  string  $payload
     * @param  string  $connectionName
     * @param  string  $queue
     * @return void
     */
    public function __construct(Container $container, $payload, $connectionName, $queue)
    {
        $this->queue = $queue;
        $this->payload = $payload;
        $this->container = $container;
        $this->connectionName = $connectionName;
    }

    /**
     * Release the job back into the queue after (n) seconds.
     *
     * @param  int  $delay
     * @return void
     */
    public function release($delay = 0)
    {
        parent::release($delay);
    }

    /**
     * Get the number of times the job has been attempted.
     *
     * @return int
     */
    public function attempts()
    {
        return 1;
    }

    /**
     * Get the job identifier.
     *
     * @return string
     */
    public function getJobId()
    {
        return '';
    }

    /**
     * Get the raw body string for the job.
     *
     * @return string
     */
    public function getRawBody()
    {
        return $this->payload;
    }

    /**
     * Get the name of the queue the job belongs to.
     *
     * @return string
     */
    public function getQueue()
    {
        return 'sync';
    }
}