Skip to content

BaseBatchedJob ​

Type
Abstract Class
Namespace
craft\queue
Inherits
craft\queue\BaseBatchedJob » craft\queue\BaseJob » yii\base\BaseObject
Implements
craft\queue\JobInterface, yii\base\Configurable
Extended by
craft\queue\BaseBatchedElementJob, craft\queue\jobs\ApplyNewPropagationMethod, craft\queue\jobs\FindAndReplace, 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

Public Properties ​

PropertyDescription
batchIndexinteger – The index of the current batch (starting with 0)
batchSizeinteger – The number of items that should be processed in a single batch
descriptionstring, null – The configured job description.
itemOffsetinteger – The offset to start fetching items by.
priorityinteger, null – The job’s priority
ttrinteger, null – The job’s TTR

batchIndex ​

Type
integer
Default value
0

The index of the current batch (starting with 0)

View source

batchSize ​

Type
integer
Default value
100

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

View source

itemOffset ​

Type
integer
Default value
0

The offset to start fetching items by.

View source

priority ​

Type
integer, null
Default value
null

The job’s priority

View source

ttr ​

Type
integer, null
Default value
null

The job’s TTR

View source

Public Methods ​

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

__sleep() ​

View source

execute() ​

View source

Arguments ​

getDescription() ​

Returns the description that should be used for the job.

View source

Returns ​

string, null

Protected Methods ​

MethodDescription
after()Does things after the last item of the last batch.
afterBatch()Does things after the last item of the current batch.
before()Does things before the first item of the first batch.
beforeBatch()Does things before the first item of the current batch.
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.

after() ​

Since
5.0.0

Does things after the last item of the last batch.

View source

afterBatch() ​

Since
5.0.0

Does things after the last item of the current batch.

View source

before() ​

Since
5.0.0

Does things before the first item of the first batch.

View source

beforeBatch() ​

Since
5.0.0

Does things before the first item of the current batch.

View source

data() ​

Returns the batchable data.

View source

Returns ​

craft\base\Batchable

loadData() ​

Loads the batchable data.

View source

Returns ​

craft\base\Batchable

processItem() ​

Processes an item.

View source

Arguments ​

  • $item (mixed)

totalBatches() ​

Returns the total number of batches.

View source

Returns ​

integer

totalItems() ​

Returns the total number of items across all the batches.

View source

Returns ​

integer