BP_Background_Process::handle()

Handle.

Description

Pass each queue item to the task handler, while remaining within server memory and time limit constraints.

Source

File: bp-core/classes/class-bp-background-process.php

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
protected function handle() {
    $this->lock_process();
 
    do {
        $batch = $this->get_batch();
 
        foreach ( $batch->data as $key => $value ) {
            $task = $this->task( $value );
 
            if ( false !== $task ) {
                $batch->data[ $key ] = $task;
            } else {
                unset( $batch->data[ $key ] );
            }
 
            if ( $this->batch_limit_exceeded() ) {
                // Batch limits reached.
                break;
            }
        }
 
        // Update or delete current batch.
        if ( ! empty( $batch->data ) ) {
            $this->update( $batch->key, $batch->data );
        } else {
            $this->delete( $batch->key );
        }
    } while ( ! $this->batch_limit_exceeded() && ! $this->is_queue_empty() );
 
    $this->unlock_process();
 
    // Start next batch or complete process.
    if ( ! $this->is_queue_empty() ) {
        $this->dispatch();
    } else {
        $this->complete();
    }
}

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.