TinyTick logoTinyTick

getTaskRunReasonText

The getTaskRunReasonText function returns a string describing the reason for a task run changing state.

getTaskRunReasonText(reason: TaskRunReason): string
TypeDescription
reasonTaskRunReason

The reason for the task run changing state.

returnsstring

A string describing the reason.

It is designed to be used for logging and diagnostic reasons with the reason parameter of listeners like TaskRunRunningListener and TaskRunFailedListener.

Example

This example registers a task run listener and then uses the getTaskRunReasonText function to get a string describing the reason for the task run changing state.

import {createManager, getTaskRunReasonText} from 'tinytick';

const manager = createManager().start();
manager.setTask('ping', async () => await fetch('https://example.org'));

const listenerId = manager.addTaskRunRunningListener(
  'ping',
  null,
  (manager, taskId, taskRunId, running, reason) =>
    console.log(
      `Task '${taskId}' changed; ${getTaskRunReasonText(reason)}`,
    ),
);

manager.scheduleTaskRun('ping');
// -> "Task 'ping' changed; scheduled"
// ... wait 100ms for task to start
// -> "Task 'ping' changed; started"
// ... wait 100ms for task to complete
// -> "Task 'ping' changed; succeeded"

manager.delListener(listenerId);

Since

v1.2.6