Content Management and Capture

 View Only

Creating a custom task for Task Manager - backend

By Aditya Holikatti posted Fri March 25, 2022 01:45 PM


Today we'll be discussing the back-end effort for creating a custom task for Task Manager. Look out for a second post that will describe details of the front-end requirements.


Introduction : 

 Task Manager is a REST web application that provides a mechanism for running and managing long-running, server-side asynchronous jobs. This means that once a customer sets a schedule, the task is run according to the schedule without requiring the User's attention.  Task Manager can be deployed as an IBM Content Navigator module in tWAS and as a container in IBM Cloud Pak. It is primarily used by IBM Enterprise Records, IBM Content Collector for SAP, and for IBM Content Navigator functions such as Teamspace Delete and Box Share. 

The design of Task Manager separates the scheduling and execution of a task from the function of the task itself. Task Manager ensures that a task runs according to the specified schedule and requires the task implementation to be provided. By virtue of this design, a Task Manager User can focus on the particulars of the task they want to run, and rely on Task Manager to run it at the required time.  


 In this blog post, you learn how to create a custom task,  which can be provided to Task Manager for scheduling and execution. A custom task can be useful when you want to automate an action that is run on a regular schedule. One example is a task which runs once a month to scrub a customer's repository of all files that belong to a specific document class.   


Important Points:

 When you write a custom task, understand that all tasks must inherit from the BaseTask. The purpose of the BaseTask is two-fold:

 1) It provides essential housekeeping functions, which include setting the task status, calculating and updating the time of the next execution, graceful error handling, and other functions. Thus, custom tasks can focus on the core functions of what the task intends to accomplish. 

 2) Because Task Manager needs to provide a scheduling framework without knowledge of the task that is being scheduled, it uses dynamic polymorphism and references objects of the custom task by using a BaseTask reference.


Requirements of a custom task:

1) Create a constructor that accepts a ‘Task’ object and a ‘File’ object. This constructor, in addition to any required initializations, must pass these arguments to the BaseTask constructor.





public class CustomTask extends BaseTask {

 public CustomTask(Task task, File file) throws IOException {

 super(task, file);



where ‘task’ is an object created by Task Manager to encapsulate a custom task and ‘file’ is the log Directory where task-specific log files, separate from Task Manager application logs, will be written. By default, this location is the same as the Task Manager application logs configured in the IBM Content Navigator Administrator Settings page.


 2) addError(Exception exception)


     To display any error message in a custom task on the client-side, the custom task can call the addError() method and pass the caught exception.


3) performTask() 


    This method, in a custom task, is started when a task runs and is the point where flow of control transfers from Task Manager to the custom task. The logic of the custom task is implemented in the performTask().

 Often, a custom task might require information from the client-side to run a task. 

 The request from the client-side contains a ‘specificTaskRequest’ JSON Object that is intended to be used for this purpose. To access this object, the following code snippet can be used:

public void performTask() {

JSONObject taskInfo = JSONObject.parse(task.getTaskInfo());

JSONObject specificTaskRequest = (JSONObject) taskInfo.get("specificTaskRequest");



Next steps :

 Once a custom task is coded, compile the code and create a jar file from the resulting class files. In an on-prem deployment on tWAS , place this jar file in the WEB-INF/dropins directory of the Task Manager exploded WAR. In a container deployment on liberty, Save the JAR file to the <external_volume_path>/extTM directory in your Task Manager environment. Once these steps are complete, Task Manager can access and schedule this task.