webCOMAND

SystemTask::start_bg_task()

Convenience method for starting a background task. Creates a new SystemTask instance in the repository and starts the process in the background.

Prototype

SystemTask start_bg_task(repo $repo, $user, $title, collection $runnables, array $params = [], array $options = [])

Parameters

  • repo - The repository instance to create the system task in.
  • user - The user invoking the task (NULL to use the authenticated repo user).
  • title - The title to assign to the task.
  • runnables - The non-empty collection of runnables to invoke.
  • params - An array of parameters to pass to the process. This must be an array of arrays whose top-level count equals the number of runnables to invoke.  Parameter array(s) must contain only primitive values (i.e. integer, float, boolean, string, or NULL).
  • options - An associative array where the key is any System Task Field Identifier and the value is the value to initialize the field to.  This is rarely used or specified because most fields are set automatically or by calling SystemTask methods after the task is created.

Return

The instantiated SystemTask for the background process, or NULL if it could not be created.

Example

require_once('/var/www/webcomand/comand.php');

use io_comand_systemtask\models\SystemTask;

$repo = comand::repo();
$runnables = $repo->get('FROM Runnable+ WHERE Identifier=?', [
    'bind' => ['RefreshCache']
]);
$task = SystemTask::start_bg_task(
    $repo,
    $user,
    'Refresh Cache',
    $runnables,
    [['--mode', 'update']],
    ['Status' => 'Initializing...']
);
if($task === NULL) {
    comand::log_error('Could not start background process.');
}