BaseBatchedJob

Type
Abstract Class
Namespace
craft\queue
Inherits
craft\queue\BaseBatchedJob » craft\queue\BaseJob » yii\base\BaseObject (opens new window)
Implements
craft\queue\JobInterface, yii\base\Configurable (opens new window)
Extended by
craft\queue\jobs\ApplyNewPropagationMethod, craft\queue\jobs\PropagateElements, craft\queue\jobs\ResaveElements
Since
4.4.0

BaseBatchedJob is the base class for large jobs that may need to spawn additional jobs to complete the workload.

WARNING

Batched jobs should always be pushed to the queue using craft\helpers\Queue::push(), so the priority and ttr settings can be maintained for additional spawned jobs.

WARNING

Spawned jobs are cloned from the current job, so any public properties that are set to objects which aren’t serialize()-friendly should be excluded via __sleep(), and any private/protected properties will need to be reset to their default values via __wakeup() to avoid uninitialized property errors.

View source (opens new window)

# Public Properties

Property Description
batchIndex integer (opens new window) – The index of the current batch (starting with 0)
batchSize integer (opens new window) – The number of items that should be processed in a single batch
description string (opens new window), null (opens new window) – The configured job description.
itemOffset integer (opens new window) – The offset to start fetching items by.
priority integer (opens new window), null (opens new window) – The job’s priority
ttr integer (opens new window), null (opens new window) – The job’s TTR

# batchIndex

Type
integer (opens new window)
Default value
0

The index of the current batch (starting with 0)

View source (opens new window)

# batchSize

Type
integer (opens new window)
Default value
100

The number of items that should be processed in a single batch

View source (opens new window)

# itemOffset

Type
integer (opens new window)
Default value
0

The offset to start fetching items by.

View source (opens new window)

# priority

Type
integer (opens new window), null (opens new window)
Default value
null

The job’s priority

View source (opens new window)

# ttr

Type
integer (opens new window), null (opens new window)
Default value
null

The job’s TTR

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__construct() (opens new window) Constructor.
__get() (opens new window) Returns the value of an object property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets value of an object property.
__sleep()
__unset() (opens new window) Sets an object property to null.
__wakeup()
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
execute()
getDescription() Returns the description that should be used for the job.
hasMethod() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) Returns a value indicating whether a property is defined.
init() Initializes the object.

# __sleep()

View source (opens new window)

# execute()

View source (opens new window)

Arguments

# getDescription()

Returns the description that should be used for the job.

View source (opens new window)

Returns

string (opens new window), null (opens new window)

# Protected Methods

Method Description
data() Returns the batchable data.
defaultDescription() Returns a default description for getDescription().
loadData() Loads the batchable data.
processItem() Processes an item.
setProgress() Sets the job progress on the queue.
totalBatches() Returns the total number of batches.
totalItems() Returns the total number of items across all the batches.

# data()

Returns the batchable data.

View source (opens new window)

Returns

craft\base\Batchable

# loadData()

Loads the batchable data.

View source (opens new window)

Returns

craft\base\Batchable

# processItem()

Processes an item.

View source (opens new window)

Arguments

  • $item (mixed)

# totalBatches()

Returns the total number of batches.

View source (opens new window)

Returns

integer (opens new window)

# totalItems()

Returns the total number of items across all the batches.

View source (opens new window)

Returns

integer (opens new window)