CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
AFTaskManager Class Reference

Task manager component of top-level framework for web applications. More...

## Public Member Functions
| QueueTask ($Callback, $Parameters=NULL, $Priority=self::PRIORITY_LOW, $Description="")
| Add task to queue. More...
| QueueUniqueTask ($Callback, $Parameters=NULL, $Priority=self::PRIORITY_LOW, $Description="")
| Add task to queue if not already in queue or currently running. More...
| TaskIsInQueue ($Callback, $Parameters=NULL)
| Check if task is already in queue or currently running. More...
| GetTaskQueueSize ($Priority=NULL)
| Retrieve current number of tasks in queue. More...
| GetQueuedTaskList ($Count=100, $Offset=0)
| Retrieve list of tasks currently in queue. More...
| GetQueuedTaskCount ($Callback=NULL, $Parameters=NULL, $Priority=NULL, $Description=NULL)
| Get number of queued tasks that match supplied values. More...
| GetRunningTaskList ($Count=100, $Offset=0)
| Retrieve list of tasks currently running. More...
| GetRunningTaskCount ()
| Retrieve count of tasks currently running. More...
| GetOrphanedTaskList ($Count=100, $Offset=0)
| Retrieve list of tasks currently orphaned. More...
| GetOrphanedTaskCount ()
| Retrieve current number of orphaned tasks. More...
| ReQueueOrphanedTask ($TaskId, $NewPriority=NULL)
| Move orphaned task back into queue. More...
| RequeueCurrentTask ($NewValue=TRUE)
| Set whether to requeue the currently-running background task when it completes. More...
| DeleteTask ($TaskId)
| Remove task from task queues. More...
| GetTask ($TaskId)
| Retrieve task info from queue (either running or queued tasks). More...
| TaskExecutionEnabled ($NewValue=DB_NOVALUE, $Persistent=FALSE)
| Get/set whether automatic task execution is enabled. More...
| MaxTasks ($NewValue=DB_NOVALUE, $Persistent=FALSE)
| Get/set maximum number of tasks to have running simultaneously. More...
| GetCurrentBackgroundPriority ()
| Determine current priority if running in background. More...
| GetNextHigherBackgroundPriority ($Priority=NULL)
| Get next higher possible background task priority. More...
| GetNextLowerBackgroundPriority ($Priority=NULL)
| Get next lower possible background task priority. More...
| RunQueuedTasks ()
| Run any queued background tasks until either remaining PHP execution time or available memory run too low. More...

## Static Public Member Functions
static | GetTaskCallbackSynopsis (array $TaskInfo)
| Get printable synopsis for task callback. More...

## Public Attributes
const | PRIORITY_HIGH = 1
| Highest priority. More...
const | PRIORITY_MEDIUM = 2
| Medium (default) priority. More...
const | PRIORITY_LOW = 3
| Lower priority. More...
const | PRIORITY_BACKGROUND = 4
| Lowest priority. More...

## Detailed Description

Task manager component of top-level framework for web applications.

Definition at line 14 of file AFTaskManager.php.

## Member Function Documentation

AFTaskManager::DeleteTask | ( |  | $TaskId | ) |

Remove task from task queues.

Parameters

  int | $TaskId | Task ID.

Returns
  int Number of tasks removed.

Definition at line 303 of file AFTaskManager.php.

AFTaskManager::GetCurrentBackgroundPriority | ( |  | ) |

Determine current priority if running in background.

Returns
  int Current background priority (PRIORITY_ value), or NULL if not currently running in background.

Definition at line 483 of file AFTaskManager.php.

Referenced by GetNextHigherBackgroundPriority(), and GetNextLowerBackgroundPriority().

Here is the caller graph for this function:

AFTaskManager::GetNextHigherBackgroundPriority | ( |  | $Priority = `NULL` | ) |

Get next higher possible background task priority.

If already at the highest priority, the same value is returned.

Parameters

  int | $Priority | Background priority (PRIORITY_ value). (OPTIONAL, defaults to current priority if running in background, or NULL if running in foreground)

Returns
  integer|null Next higher background priority, or NULL if no priority specified and currently running in foreground.

Definition at line 498 of file AFTaskManager.php.

References GetCurrentBackgroundPriority().

AFTaskManager::GetNextLowerBackgroundPriority | ( |  | $Priority = `NULL` | ) |

Get next lower possible background task priority.

If already at the lowest priority, the same value is returned.

Parameters

  int | $Priority | Background priority (PRIORITY_ value). (OPTIONAL, defaults to current priority if running in background, or NULL if running in foreground)

Returns
  integer|null Next lower background priority, or NULL if no priority specified and currently running in foreground.

Definition at line 521 of file AFTaskManager.php.

References GetCurrentBackgroundPriority().

AFTaskManager::GetOrphanedTaskCount | ( |  | ) |

Retrieve current number of orphaned tasks.

Returns
  Number of orphaned tasks.

Definition at line 256 of file AFTaskManager.php.

AFTaskManager::GetOrphanedTaskList | ( |  | $Count = `100`,
|  |  | $Offset = `0`
| ) |  |

Retrieve list of tasks currently orphaned.

Parameters

  int | $Count | Number to retrieve. (OPTIONAL, defaults to 100)
  int | $Offset | Offset into queue to start retrieval. (OPTIONAL)

Returns
  Array with task IDs for index and task info for values. Task info is stored as associative array with "Callback" and "Parameter" indices.

Definition at line 244 of file AFTaskManager.php.

AFTaskManager::GetQueuedTaskCount | ( |  | $Callback = `NULL`,
|  |  | $Parameters = `NULL`,
|  |  | $Priority = `NULL`,
|  |  | $Description = `NULL`
| ) |  |

Get number of queued tasks that match supplied values.

Tasks will not be counted if the values do not match exactly, so callbacks with methods for different objects (even of the same class) will not match.

Parameters

  callback | $Callback | Function or method to call to perform task. (OPTIONAL)
  array | $Parameters | Array containing parameters to pass to function or method. Pass in empty array to match tasks with no parameters. (OPTIONAL)
  int | $Priority | Priority to assign to task. (OPTIONAL)
  string | $Description | Text description of task. (OPTIONAL)

Returns
  int Number of tasks queued that match supplied parameters.

Definition at line 183 of file AFTaskManager.php.

Referenced by GetTaskQueueSize().

Here is the caller graph for this function:

AFTaskManager::GetQueuedTaskList | ( |  | $Count = `100`,
|  |  | $Offset = `0`
| ) |  |

Retrieve list of tasks currently in queue.

Parameters

  int | $Count | Number to retrieve. (OPTIONAL, defaults to 100)
  int | $Offset | Offset into queue to start retrieval. (OPTIONAL)

Returns
  array Array with task IDs for index and task info for values. Task info is stored as associative array with "Callback" and "Parameter" indices.

Definition at line 164 of file AFTaskManager.php.

AFTaskManager::GetRunningTaskCount | ( |  | ) |

Retrieve count of tasks currently running.

Returns
  Number of running tasks.

Definition at line 229 of file AFTaskManager.php.

Referenced by RunQueuedTasks().

Here is the caller graph for this function:

AFTaskManager::GetRunningTaskList | ( |  | $Count = `100`,
|  |  | $Offset = `0`
| ) |  |

Retrieve list of tasks currently running.

Parameters

  int | $Count | Number to retrieve. (OPTIONAL, defaults to 100)
  int | $Offset | Offset into queue to start retrieval. (OPTIONAL)

Returns
  Array with task IDs for index and task info for values. Task info is stored as associative array with "Callback" and "Parameter" indices.

Definition at line 217 of file AFTaskManager.php.

AFTaskManager::GetTask | ( |  | $TaskId | ) |

Retrieve task info from queue (either running or queued tasks).

Parameters

  int | $TaskId | Task ID.

Returns
  Array with task info for values or NULL if task is not found. Task info is stored as associative array with "Callback" and "Parameter" indices.

Definition at line 319 of file AFTaskManager.php.

Referenced by RunQueuedTasks().

Here is the caller graph for this function:

static AFTaskManager::GetTaskCallbackSynopsis | ( | array | $TaskInfo | ) |
| static

Get printable synopsis for task callback.

Any string values in the callback parameter list will be escaped with htmlspecialchars().

Parameters

  array | $TaskInfo | Array of task info as returned by GetTask().

Returns
  string Task callback synopsis string.

See also
  AFTaskManager::GetTask()

Definition at line 396 of file AFTaskManager.php.

AFTaskManager::GetTaskQueueSize | ( |  | $Priority = `NULL` | ) |

Retrieve current number of tasks in queue.

Parameters

  int | $Priority | Priority of tasks. (OPTIONAL, defaults to all priorities)

Returns
  int Number of tasks currently in queue.

Definition at line 152 of file AFTaskManager.php.

References GetQueuedTaskCount().

Referenced by RunQueuedTasks().

Here is the caller graph for this function:

AFTaskManager::MaxTasks | ( |  | $NewValue = `DB_NOVALUE`,
|  |  | $Persistent = `FALSE`
| ) |  |

Get/set maximum number of tasks to have running simultaneously.

Parameters

  int | $NewValue | New setting for max number of tasks. (OPTIONAL)
  bool | $Persistent | If TRUE the new value will be saved (i.e. persistent across page loads), otherwise the value will apply to just the current page load. (OPTIONAL, defaults to FALSE)

Returns
  Current maximum number of tasks to run at once.

Definition at line 384 of file AFTaskManager.php.

Referenced by RunQueuedTasks().

Here is the caller graph for this function:

AFTaskManager::QueueTask | ( |  | $Callback,
|  |  | $Parameters = `NULL`,
|  |  | $Priority = `self::PRIORITY_LOW`,
|  |  | $Description = `""`
| ) |  |

Add task to queue.

The Callback parameters is the PHP "callback" type. If $Callback refers to a function (rather than an object method) that function must be available in a global scope on all pages or must be loadable by ApplicationFramework::LoadFunction(). If $Priority is out-of-bounds, it wil be normalized to be within bounds.

Parameters

  callback | $Callback | Function or method to call to perform task.
  array | $Parameters | Array containing parameters to pass to function or method. (OPTIONAL, pass NULL for no parameters)
  int | $Priority | Priority to assign to task. (OPTIONAL, defaults to PRIORITY_LOW)
  string | $Description | Text description of task. (OPTIONAL)

Definition at line 54 of file AFTaskManager.php.

Referenced by QueueUniqueTask().

Here is the caller graph for this function:

AFTaskManager::QueueUniqueTask | ( |  | $Callback,
|  |  | $Parameters = `NULL`,
|  |  | $Priority = `self::PRIORITY_LOW`,
|  |  | $Description = `""`
| ) |  |

Add task to queue if not already in queue or currently running.

If task is already in queue with a lower priority than specified, the task's priority will be increased to the new value. The Callback parameter is the PHP "callback" type. If $Callback refers to a function (rather than an object method) that function must be available in a global scope on all pages or must be loadable by ApplicationFramework::LoadFunction(). If $Priority is out-of-bounds, it wil be normalized to be within bounds.

Parameters

  callback | $Callback | Function or method to call to perform task.
  array | $Parameters | Array containing parameters to pass to function or method. (OPTIONAL, pass NULL for no parameters)
  int | $Priority | Priority to assign to task. (OPTIONAL, defaults to PRIORITY_LOW)
  string | $Description | Text description of task. (OPTIONAL)

Returns
  bool TRUE if task was added, otherwise FALSE.

See also
  AFTaskManager::TaskIsInQueue()

Definition at line 88 of file AFTaskManager.php.

References QueueTask(), and TaskIsInQueue().

AFTaskManager::RequeueCurrentTask | ( |  | $NewValue = `TRUE` | ) |

Set whether to requeue the currently-running background task when it completes.

Parameters

  bool | $NewValue | If TRUE, current task will be requeued. (OPTIONAL, defaults to TRUE)

Definition at line 293 of file AFTaskManager.php.

Referenced by RunQueuedTasks().

Here is the caller graph for this function:

AFTaskManager::ReQueueOrphanedTask | ( |  | $TaskId,
|  |  | $NewPriority = `NULL`
| ) |  |

Move orphaned task back into queue.

Parameters

  int | $TaskId | Task ID.
  int | $NewPriority | New priority for task being requeued. (OPTIONAL)

Definition at line 269 of file AFTaskManager.php.

AFTaskManager::RunQueuedTasks | ( |  | ) |

Run any queued background tasks until either remaining PHP execution time or available memory run too low.

Definition at line 539 of file AFTaskManager.php.

References DB_NOVALUE, ApplicationFramework\GetFreeMemory(), ApplicationFramework\GetPercentFreeMemory(), ApplicationFramework\GetPhpMemoryLimit(), GetRunningTaskCount(), GetTask(), GetTaskQueueSize(), Database\INT_MAX_VALUE, ApplicationFramework\LOGLVL_DEBUG, MaxTasks(), and RequeueCurrentTask().

AFTaskManager::TaskExecutionEnabled | ( |  | $NewValue = `DB_NOVALUE`,
|  |  | $Persistent = `FALSE`
| ) |  |

Get/set whether automatic task execution is enabled.

(This does not prevent tasks from being manually executed.)

Parameters

  bool | $NewValue | TRUE to enable or FALSE to disable. (OPTIONAL)
  bool | $Persistent | If TRUE the new value will be saved (i.e. persistent across page loads), otherwise the value will apply to just the current page load. (OPTIONAL, defaults to FALSE)

Returns
  bool Returns TRUE if automatic task execution is enabled or otherwise FALSE.

Definition at line 370 of file AFTaskManager.php.

AFTaskManager::TaskIsInQueue | ( |  | $Callback,
|  |  | $Parameters = `NULL`
| ) |  |

Check if task is already in queue or currently running.

When no $Parameters value is specified the task is checked against any other entries with the same $Callback.

Parameters

  callback | $Callback | Function or method to call to perform task.
  array | $Parameters | Array containing parameters to pass to function or method. (OPTIONAL)

Returns
  bool TRUE if task is already in queue, otherwise FALSE.

Definition at line 129 of file AFTaskManager.php.

Referenced by QueueUniqueTask().

Here is the caller graph for this function:

## Member Data Documentation

const AFTaskManager::PRIORITY_BACKGROUND = 4

Lowest priority.

Definition at line 39 of file AFTaskManager.php.

const AFTaskManager::PRIORITY_HIGH = 1

Highest priority.

Definition at line 33 of file AFTaskManager.php.

const AFTaskManager::PRIORITY_LOW = 3

Lower priority.

Definition at line 37 of file AFTaskManager.php.

const AFTaskManager::PRIORITY_MEDIUM = 2

Medium (default) priority.

Definition at line 35 of file AFTaskManager.php.

The documentation for this class was generated from the following file:

- lib/ScoutLib/AFTaskManager.php