Commands(name?) : []

Returns available commands for background tasks.

Commands Parameters

name? : ?
String name to return command descriptor, true to get all commands, omit to get all names.

CreateTask(command, parameters?, callback?, name?, at?, priority = 0, paused = false, user?) : BackgroundTask

Creates a task to execute in background.

CreateTask Parameters

command : String
Known background command (built-in or custom script).

parameters? : Dict?
Command parameters (specific to command).
There are some special parameters that apply to all commands:

  • $Transaction : Boolean
    To postpone the task execution until the current transaction finishes (or cancel the task if the transaction fails).
  • $Critical : Boolean
    To mark task as critical, so an error log record is created and an error report email is sent if the task fails.
  • $FailAttempts : Integer
    Number of attempts to try re-executing the task if it failed. Set to -1 to retry until the task succeeds.
  • $FailWaitSeconds : Integer
    Number of seconds to wait before the next attempt after fail.
  • $FailWaitMultiplier : Integer
    The number of seconds to wait is calculated by the formula: $FailWaitSeconds * (1 + $FailWaitMultiplier * Task.CurrentAttempt).
  • $MaxResults : Integer
    Maximum length of the task results history. Set to 0 (default) to not limit the history, set to -1 to not track results history.
  • $Simulate : Boolean
    To execute task in simulation mode.
  • $Name : String
    Task name if not set by the ‘name’ argument.

callback? : Function?
Callback function ((result, task) => body) to be called after the task finishes, with special context variables $Task and $Result.
$Result variable (and result argument) is a dictionary { Succeeded : boolean, Error : Error, Result : Dict }.

name? : String?
Background task name.

at? : DateTime?
If not null, then specifies the time when the task should be started.
Otherwise, the task will be started immediately (as soon as possible).
If DateTime, then starts at the specified time (UTC).
If Date, then starts at the beginning of the specified date (in UTC).
If Time, then specifies the time in UTC for the current date.
If Duration, then specifies the time span from now to start the task.
If Number, then specifies the number of seconds from now to start the task.

priority : Integer = 0
The greater is the number, the higher is the priority of the task.

paused : Boolean = false
True to create paused task.

user? : Identity?
The task will be running on behalf of the specified user (current user by default).

CreateTask Examples

var task = CreateTask('AddTeamMember', { Team = Team('Solution Managers'), Member = $User });

Schedule(task, at?, priority?, failAttempts?, failWaitSeconds?, failWaitMultiplier?, maxResults?) : BackgroundTask?

Schedules an existing background task to execute once again.

Schedule Parameters

task : BackgroundTask?

at? : DateTime?
If not null, then specifies the time when the task should be started.
Otherwise, the task will be started immediately (as soon as possible).
If DateTime, then starts at the specified time (UTC).
If Date, then starts at the beginning of the specified date (in UTC).
If Time, then specifies the time in UTC for the current date.
If Duration, then specifies the time span from now to start the task.
If Number, then specifies the number of seconds from now to start the task.

priority? : Integer?
Skip or set to null to keep current priority.

failAttempts? : Integer?
Skip or set to null to keep current value.

failWaitSeconds? : Integer?
Skip or set to null to keep current value.

failWaitMultiplier? : Integer?
Skip or set to null to keep current value.

maxResults? : Integer?
Skip or set to null to keep current value.

Schedule Examples

$Task.Schedule(); // as soon as possible
$Task.Schedule(10); // after 10 seconds;
$Task.Schedule(Duration(0, 1)); // after 1 minute

Task(nameOrId, required = true, bycommand = false) : BackgroundTask?

Returns a background task by unique name or ID.

Task Parameters

nameOrId : String
Can be task ID (integer, preferred), task name (should be unique) or task command (should be unique in the queue).

required : Boolean = true
False to not fail if task was not found and return null.

bycommand : Boolean = false
True to use nameOrId as task command name.

Task Examples

var task = Task(1001);
var task = Task('Some unique task name', false);

UpdateParameters(task, params, reset = false) : BackgroundTask?

Updates parameters of a background task.

UpdateParameters Parameters

task : BackgroundTask?

params : Dict?
Parameters to update.

reset : Boolean = false
If true, then all old parameters will be removed.
If false, then all existing keys will be overwritten and all new keys will be added.

UpdateParameters Examples

$Task.UpdateParameters({ SomeParam = true });

Leave a Comment

Your email address will not be published. Required fields are marked *