class PushTask (View source)

A PushTask encapsulates a unit of work that an application places onto a Push Queue for asynchronous execution. The queue executes that work by sending the task back to the application in the form of an HTTP request to one of the application's handlers.

This class is immutable.

Constants

MAX_DELAY_SECONDS

A task may be scheduled up to 30 days into the future.

MAX_NAME_LENGTH

MAX_TASK_SIZE_BYTES

MAX_URL_LENGTH

NAME_PATTERN

Methods

__construct(string $url_path, array $query_data = [], array $options = [])

Construct a PushTask.

string
getUrl()

Return the task's URL. This will be the task's URL path, plus any query parameters if the task's method is GET, HEAD, or DELETE.

array
getQueryData()

Return the task's query data.

string
getName()

Return the task's name if it was explicitly named.

float
getDelaySeconds()

Return the task's execution delay, in seconds.

string
getMethod()

Return the task's HTTP method.

string[]
getHeaders()

Return the task's headers.

string
add($queue_name = 'default')

Adds the task to a queue.

Details

__construct(string $url_path, array $query_data = [], array $options = [])

Construct a PushTask.

Parameters

string $url_path The path of the URL handler for this task relative to your application's root directory.
array $query_data The data carried by task, typically in the form of a set of key value pairs. This data will be encoded using http_build_query() and will be either:

  • Added to the payload of the HTTP request if the task's method is POST or PUT.
  • Added to the URL if the task's method is GET, HEAD, or DELETE.
array $options Additional options for the task. Valid options are:

  • 'method': string One of 'POST', 'GET', 'HEAD', 'PUT', 'DELETE'. Default value: 'POST'.
  • 'name': string Name of the task. Defaults to '' meaning the service will generate a unique task name.
  • 'delay_seconds': float The minimum time to wait before executing the task. Default: zero.
  • 'header': string Additional headers to be sent when the task executes. Note: The 'Content-Type' header cannot be specified.

Exceptions

InvalidArgumentException if

<

ul>

  • A supplied argument is not the correct type.
  • Any of the specified options are invalid.
  • The header 'content-type' is specified.
  • Any supplied headers are not of the format 'key:value'.
  • string getUrl()

    Return the task's URL. This will be the task's URL path, plus any query parameters if the task's method is GET, HEAD, or DELETE.

    Return Value

    string The task's URL path.

    array getQueryData()

    Return the task's query data.

    Return Value

    array The task's query data.

    string getName()

    Return the task's name if it was explicitly named.

    Return Value

    string The task's name if it was explicity named, or empty string if it will be given a uniquely generated name in the queue.

    float getDelaySeconds()

    Return the task's execution delay, in seconds.

    Return Value

    float The task's execution delay in seconds.

    string getMethod()

    Return the task's HTTP method.

    Return Value

    string The task's HTTP method: 'DELETE', 'GET', 'HEAD', 'POST', or 'PUT'.

    string[] getHeaders()

    Return the task's headers.

    Return Value

    string[] The headers that will be sent when the task is executed. This list is not exhaustive as the backend may add more headers at execution time. The array is numerically indexed and of the same format as that returned by the standard headers_list() function.

    string add($queue_name = 'default')

    Adds the task to a queue.

    Parameters

    $queue_name

    Return Value

    string The name of the task.

    Exceptions

    TaskAlreadyExistsException if a task of the same name already exists in the queue.
    TaskQueueException if there was a problem using the service.