Tasks

Introduction to tasks in ConSol CM

Tasks are used to execute scripts asynchronously, so that script execution is not tied to user actions in the Web Client or CM/Track. Tasks can be used for general operations and operations whose processing takes long, so that it would cause a timeout when executed as a regular script.

Concepts, terms and definitions

Concept

Other terms

Definition

task

 

Asynchronous execution of a script

task script

 

Script which implements the operations performed by a task and the task behavior if an error occurs or the task is canceled

task executor

 

Module which scans the database for new scheduled tasks and executes them

task descriptor

 

Internal object which holds information about a task

execution specification

 

Internal object which hold information about the start date and time of the task; if not specified, the task is started immediately

Purpose and usage

Tasks enable asynchronous operations. They can be created either manually in the Web Admin Suite or automatically in a script. In both cases, the task is based on a script of the type Task which implements the logic of the operations to be performed. Tasks can be used for operations which are not related to specific user actions in the Web Client or CM/Track, e.g. general maintenance work. In addition, tasks allow to perform operations whose processing takes long, so that it would cause a timeout when executed as a regular script.

Tasks can permanently delete objects from the ConSol CM database. The actions performed by a task cannot be undone. Tasks performing bulk operations can have a severe impact on system performance.

Available settings for task execution

The following settings are available for task execution in general:

Basic tasks

You need to perform the following steps to use tasks in ConSol CM:

  1. Create a task script which implements the logic of the operations to be performed, see Creating a task script.
  2. Create a task which executes the task script, see Creating a task.
  3. You can track the task’s progress in the task list, see Tracking the task execution.

Creating a task script

Create a script of the type Task on the Scripts page of the Web Admin Suite (see Scripts). The script has to implement the logic of the operations to be performed.

The task script needs to implement the following four methods:

Creating a task

There are two ways to create a task:

Tracking the task execution

The task list shows all active tasks in the system. The following information is displayed for each task:

You can search the table by task name or status, or apply a filter to display tasks with a certain scheduling interval or status.

Periodic tasks with several planned executions are grouped by default. This means that only the next execution is displayed. The Scheduling option column contains the number of planned executions and a clock icon to see all scheduling options. The Next execution at column shows the data for the next execution and you can hover the clock icon the see all executions. If you want to display each scheduled execution in its own row, e.g. to deactivate or cancel one execution only, you can deselect the Only next executions checkbox.

Advanced tasks

Canceling a task

There are two ways to cancel a running task:

Canceled tasks are removed and cannot be started again.

Deactivating a task

By clicking the Deactivate icon, you can deactivate a task with the status Waiting for execution which is needed for the proper functioning of the system but should not be executed at the moment. Deactivated tasks remain in the task list with the status Deactivated. They can be executed again by clicking the Activate icon.

When planning a periodic task, you can select the option Deactivate task after error to deactivate the task if an error occurs during task execution. This affects only the scheduled execution for which the error occurs.

Repeating a task

There are two scenarios where you might want to repeat a task:

In both cases you can use the following method to repeat the task:

return new ExecutionSpecification().setRetryRequested(true);

If you want to set a specific date or time when the repeated task should be executed, use:

return new ExecutionSpecification().setRetryRequested(true).setExecutionDate(new Date(new Date().getTime() + 15000));

Add this piece of code to the end of the onExecute() method in the task script, if you want repeat the task in the regular execution. If you want to repeat the task if an error occurred, add it to the onError() method.

Using the context reference

If you create tasks from other scripts, you can use the context reference to determine which script created the task. When creating the task, you set a context reference, which can be retrieved in the task script to implement a different behavior depending on the source script.