Skip to main content

Gravity_Forms\Gravity_Forms\Async\GF_Background_Process

Abstract GF_Background_Process class.

Based on WP_Background_Process https://github.com/A5hleyRich/wp-background-processing/blob/master/classes/wp-background-process.php

Since:

  • 2.2
  • 2.9.8 (Namespaced.)

Source: includes/async/class-gf-background-process.php:28

Details

  • Kind: class
  • Namespace: Gravity_Forms\Gravity_Forms\Async
  • Extends: WP_Async_Request

Properties

PropertyTypeDescription
$actionstringAction
$start_timeintStart time of current process.
$cron_hook_identifiermixedCron_hook_identifier
$cron_interval_identifiermixedCron_interval_identifier
$allowed_batch_data_classesbool | arrayRestrict object instantiation when using unserialize.
$current_batchobject | nullNull or the current batch.
$current_taskmixed | nullNull or the current task.
$supports_attemptsboolIndicates if the task uses an array that supports the attempts key.

Methods

MethodDescription
__construct()Initiate new background process
dispatch_on_shutdown()Uses the shutdown hook to dispatch the queued tasks so completion of the current request (e.g., form submission) is not delayed.
dispatch()Dispatches the queued tasks to Admin Ajax for processing and schedules a cron job in case processing fails.
push_to_queue()Push to queue
save()Save queue
update()Update queue
delete()Delete batch from queue.
delete_all()Delete entire job queue.
cancel()Cancel job on next batch.
is_cancelled()Has the process been cancelled?
pause()Pause job on next batch.
is_paused()Has the process been paused?
resume()Resume job.
is_queued()Is queued?
is_active()Is the tool currently active, e.g. starting, working, paused or cleaning up?
maybe_handle()Maybe process queue
is_processing()Is the background process currently running?
lock_process()Lock process
unlock_process()Unlock process
get_batches()Get batches.
shutdown_error_handler()Detects if an error occurred before the shutdown hook was triggered, and then triggers logging of the error details.
get_cron_interval()Get the cron healthcheck interval in minutes.
schedule_cron_healthcheck()Schedule cron healthcheck
handle_cron_healthcheck()Handle cron healthcheck
clear_scheduled_events()Clears all scheduled events.
cancel_process()Cancel Process
clear_queue()Clears all batches from the queue.
should_continue()Should any processing continue?
get_identifier()Get the string used to identify this type of background process.
get_chain_id()Return the current background process chain's ID.
filter_dispatch_query_args()Filters the query arguments used during an async request.
filter_dispatch_post_args()Filters the post arguments used during an async request.
filter_form()Allows filtering of the form before the task is processed.
is_valid_blog()Determines if the specified blog is suitable for batch processing.
delete_site_batches()Deletes the site batches when the site is deleted.
delete_batches()Deletes batches from the database.
log_debug()Writes a message to the core log.
log_error()Writes an error message to the core log.
uninstall()Performs some cleanup when the plugin is uninstalled.

Method Reference

__construct()

public function __construct( $allowed_batch_data_classes=true )

Initiate new background process

Parameters

NameTypeDefaultDescription
$allowed_batch_data_classesbool | arraytrueOptional. Array of class names that can be unserialized. Default true (any class).

Since: 2.2

Source: includes/async/class-gf-background-process.php:160

dispatch_on_shutdown()

public function dispatch_on_shutdown()

Uses the shutdown hook to dispatch the queued tasks so completion of the current request (e.g., form submission) is not delayed.

Returns

  • void

Since: 2.9.24 (The blocking => false arg set in get_post_args() and the 0.01 timeout set in filter_dispatch_post_args() don't work as expected: https://github.com/WordPress/Requests/issues/826)

Source: includes/async/class-gf-background-process.php:203

dispatch()

public function dispatch()

Dispatches the queued tasks to Admin Ajax for processing and schedules a cron job in case processing fails.

Returns

  • array | \WP_Error | false — HTTP Response array, WP_Error on failure, or false if not attempted.

Since: 2.2

Source: includes/async/class-gf-background-process.php:226

push_to_queue()

public function push_to_queue( $data )

Push to queue

Parameters

NameTypeDefaultDescription
$datamixedData.

Returns

  • $this

Since: 2.2

Source: includes/async/class-gf-background-process.php:279

save()

public function save()

Save queue

Returns

  • $this

Since:

  • 2.2
  • 2.9.7 (Added timestamps to the data array.)

Source: includes/async/class-gf-background-process.php:293

update()

public function update( $key, $data )

Update queue

Parameters

NameTypeDefaultDescription
$keystringKey.
$dataarrayData.

Returns

  • $this

Since:

  • 2.2
  • 2.9.7 (Added timestamps to the data array.)

Source: includes/async/class-gf-background-process.php:337

delete()

public function delete( $key )

Delete batch from queue.

Parameters

NameTypeDefaultDescription
$keystringKey.

Returns

  • $this

Source: includes/async/class-gf-background-process.php:382

delete_all()

public function delete_all()

Delete entire job queue.

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:403

cancel()

public function cancel()

Cancel job on next batch.

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:416

is_cancelled()

public function is_cancelled()

Has the process been cancelled?

Returns

  • bool

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:430

pause()

public function pause( $set_timestamp=false )

Pause job on next batch.

Parameters

NameTypeDefaultDescription
$set_timestampboolfalseIndicates of the timestamp option should be set, so it can be used by the cron healthcheck to automatically resume processing.

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:450

is_paused()

public function is_paused()

Has the process been paused?

Returns

  • bool

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:465

resume()

public function resume( $dispatch=true )

Resume job.

Parameters

NameTypeDefaultDescription
$dispatchbooltrueIndicates if the Ajax request to trigger processing of the queue should be sent.

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:485

is_queued()

public function is_queued()

Is queued?

Returns

  • bool

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:515

is_active()

public function is_active()

Is the tool currently active, e.g. starting, working, paused or cleaning up?

Returns

  • bool

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:526

maybe_handle()

public function maybe_handle()

Maybe process queue

Checks whether data exists within the queue and that the process is not already running.

Returns

  • void | mixed

Since: 2.2

Source: includes/async/class-gf-background-process.php:603

is_processing()

public function is_processing()

Is the background process currently running?

Returns

  • bool

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:687

lock_process()

public function lock_process( $reset_start_time=true )

Lock process

Lock the process so that multiple instances can't run simultaneously. Override if applicable, but the duration should be greater than that defined in the time_exceeded() method.

Parameters

NameTypeDefaultDescription
$reset_start_timebooltrueOptional, default true.

Since: 2.2

Source: includes/async/class-gf-background-process.php:707

unlock_process()

public function unlock_process()

Unlock process

Unlock the process so that other instances can spawn.

Returns

  • $this

Since: 2.2

Source: includes/async/class-gf-background-process.php:749

get_batches()

public function get_batches( $limit=0 )

Get batches.

Parameters

NameTypeDefaultDescription
$limitint0Number of batches to return, defaults to all.

Returns

  • array — of stdClass

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:795

shutdown_error_handler()

public function shutdown_error_handler()

Detects if an error occurred before the shutdown hook was triggered, and then triggers logging of the error details.

Returns

  • void

Since: 2.9.9

Source: includes/async/class-gf-background-process.php:1156

get_cron_interval()

public function get_cron_interval()

Get the cron healthcheck interval in minutes.

Default is 5 minutes, minimum is 1 minute.

Returns

  • int

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:1322

schedule_cron_healthcheck()

public function schedule_cron_healthcheck( $schedules )

Schedule cron healthcheck

Parameters

NameTypeDefaultDescription
$schedulesmixedSchedules.

Returns

  • mixed

Since: 2.2

Source: includes/async/class-gf-background-process.php:1345

handle_cron_healthcheck()

public function handle_cron_healthcheck()

Handle cron healthcheck

Restart the background process if not already running and data exists in the queue.

Since: 2.2

Source: includes/async/class-gf-background-process.php:1371

clear_scheduled_events()

public function clear_scheduled_events()

Clears all scheduled events.

Since: 2.3.1.x

Source: includes/async/class-gf-background-process.php:1468

cancel_process()

public function cancel_process()

Cancel Process

Stop processing queue items, clear cronjob and delete batch.

Since: 2.2

Source: includes/async/class-gf-background-process.php:1479

clear_queue()

public function clear_queue( $all_blogs_in_network=false )

Clears all batches from the queue.

Parameters

NameTypeDefaultDescription
$all_blogs_in_networkboolfalse

Returns

  • false | int

Since: 2.3

Source: includes/async/class-gf-background-process.php:1492

should_continue()

public function should_continue()

Should any processing continue?

Returns

  • bool

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:1544

get_identifier()

public function get_identifier()

Get the string used to identify this type of background process.

Returns

  • string

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:1580

get_chain_id()

public function get_chain_id()

Return the current background process chain's ID.

Returns

  • string

Since:

  • 2.9.7
  • 2.9.8 (Added the Ajax request action check. If the chain's ID hasn't been set before this function is first used, and hasn't been passed as a query arg during dispatch, the chain ID will be generated before being returned.)

Source: includes/async/class-gf-background-process.php:1596

filter_dispatch_query_args()

public function filter_dispatch_query_args( $args )

Filters the query arguments used during an async request.

Parameters

NameTypeDefaultDescription
$argsarrayCurrent query args.

Returns

  • array

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:1627

filter_dispatch_post_args()

public function filter_dispatch_post_args( $args )

Filters the post arguments used during an async request.

Parameters

NameTypeDefaultDescription
$argsarrayCurrent post args.

Returns

  • array

Since: 2.9.10

Source: includes/async/class-gf-background-process.php:1642

filter_form()

public function filter_form( $form, $entry )

Allows filtering of the form before the task is processed.

Parameters

NameTypeDefaultDescription
$formarrayThe form being processed.
$entryarrayThe entry being processed.

Returns

  • array

Since: 2.6.9

Source: includes/async/class-gf-background-process.php:1699

is_valid_blog()

public function is_valid_blog( $blog_id )

Determines if the specified blog is suitable for batch processing.

Parameters

NameTypeDefaultDescription
$blog_idintThe blog ID.

Returns

  • bool

Since: 2.8.16

Source: includes/async/class-gf-background-process.php:1715

delete_site_batches()

public function delete_site_batches( $old_site )

Deletes the site batches when the site is deleted.

Parameters

NameTypeDefaultDescription
$old_siteWP_Site | intThe deleted site object or ID.

Returns

  • void

Since: 2.8.16

Source: includes/async/class-gf-background-process.php:1730

delete_batches()

public function delete_batches( $all_blogs_in_network=false )

Deletes batches from the database.

Parameters

NameTypeDefaultDescription
$all_blogs_in_networkbool | intfalseTrue to delete batches for all blogs. False to delete batches for the current blog. A blog ID to delete batches for the specified blog.

Returns

  • bool | int

Since: 2.8.16

Source: includes/async/class-gf-background-process.php:1744

log_debug()

public function log_debug( $message )

Writes a message to the core log.

Parameters

NameTypeDefaultDescription
$messagestringThe message to be logged.

Returns

  • void

Since: 2.9.7

Source: includes/async/class-gf-background-process.php:1786

log_error()

public function log_error( $message )

Writes an error message to the core log.

Parameters

NameTypeDefaultDescription
$messagestringThe message to be logged.

Returns

  • void

Since: 2.9.9

Source: includes/async/class-gf-background-process.php:1799

uninstall()

public function uninstall()

Performs some cleanup when the plugin is uninstalled.

Returns

  • void

Since: 2.9.25

Source: includes/async/class-gf-background-process.php:1821