Class: Task

Task

Source:

Members

(readonly) context :Context

Task context.
Type:
Source:

(readonly) input :object

Input parameters of the Task.
Type:
  • object
Source:

(readonly) name :string

Task name.
Type:
  • string
Source:

(readonly) trackingData :object

Gets the tracking Data of the task.
Type:
  • object
Source:

Methods

acquireLock(name, retryTimeoutopt) → {Promise.<RunLock>}

Acquires a Run Lock.

A Run Lock is a way to lock resources and prevent conflicts when several task runs modify the same resource. The first task run to acquire the lock can access the resource, and other runs must wait until the resource is unlocked. You must define an arbitrary ID, which is the lock name. This method returns a representation of a Run Lock.

Example of usage:
    const myLock = await task.acquireLock('MyLockName');
    if (myLock.success) {
        // lock is acquired
        // work on synchronized resource...
        await myLock.release();
    }

Optionally, you can set a retry timeout to acquireLock. In this case, it retries every 5 seconds to acquire the lock if the lock is already held by another run:

    const myLock = await task.acquireLock('MyLockName', 15); // retry timeout of 15 seconds
    if (myLock.success) { // lock was acquired before the timeout
        // lock is acquired
        // work on synchronized resource...
        await myLock.release();
    } else {
        // after 3 attempts (1 attempt every 5 seconds) the lock is still held by another run.
    }

Note: the retry timeout is rounded to fit with the retry frequency of 5 seconds. For example, if you set 12 seconds it retries up to 3 times.

If the lock is not explicitly released, it is automatically released when the Task run ends, whether the run succeeds or fails.

Parameters:
Name Type Attributes Description
name string the name of the lock
retryTimeout int <optional>
optional maximum amount of time in seconds to wait for a lock to be available. A retry occurs every 5 seconds.
Source:
Returns:
a run lock.
Type
Promise.<RunLock>

addTrackingData(key, value)

Adds tracking Data if not null or undefined.
Parameters:
Name Type Description
key string A key of tracking Data
value number | boolean | string | object | array A value (Data)
Source:

getGuardrail(name) → {Guardrail}

Gets a Guardrail from the Task.
Parameters:
Name Type Description
name string A valid Guardrail name.
Source:
Throws:
Guardrail is not present.
Type
Error
Returns:
The requested Guardrail
Type
Guardrail

getSkill(name) → {Skill}

Gets a Skill from the Task.
Parameters:
Name Type Description
name string A valid Skill name.
Source:
Throws:
Skill is not present.
Type
Error
Returns:
The requested Skill
Type
Skill

sendTrackingEvent(data) → {Promise.<void>}

Sending directly tracking Data if not null or undefined.
Parameters:
Name Type Description
data object An object to be sent (Data)
Source:
Returns:
The promise of sending the tracking event
Type
Promise.<void>