Tasks Manager

At times, it will be necessary to carry out certain repetitive procedures in the application, such as checking rack usage in the inventory or retrieving users from an OLT. To facilitate the execution of these recurring tasks, the application includes a Task Manager module. This module allows for the flexible creation and execution of tasks by defining scripts that can run under various conditions. Additionally, tasks created in this module can be scheduled for execution as needed by the user, using the Job Scheduler Module.

Figure 1 illustrates the module's structure. In the application, when creating a task, it can be linked to a Job through the HAS_TASK relationship, indicating that the task will be executed according to the schedule defined in the Job using the Job Scheduler module. Similarly, users can be assigned to the task, represented by the SUBSCRIBED_TO relationship. In the current version of the application, these users are for informational purposes only; however, their functionalities will be implemented in future versions of the application.

Task Manager Module Structure
Figure 1. Task manager module

This module is part of the Administration category, as shown in Figure 2.

Task Manager Module
Figure 2. Task manager module

Once opened, we will see the main window of the module, as shown in Figure 3. From here, we can view the tasks currently created in the application.

Task Main Window
Figure 3. Tasks manager main window

Task

A task consists of the following properties:

PropertyDescription
NameName of the task
DescriptionDescription of the task
EnableFlag to enable or disable the execution of the task
CommitOnExecuteFlag to enable or disable if this task commit the changes in data base (if any) after its execution
ScriptThe Groovy script to be executed by this task.
ParametersList of parameters as a set of parameter name/value pairs used in the script
StartTimeThe exact time and date the task should be executed.(Optional)
EveryXMinutesInterval should this task be executed.(Optional)
ExecutionTypeHow the task should be executed.(Optional)
EmailThe email of the person or group that will receive the notification (Optional).
NotificationTypeWhat type of notification should the subscribed.(Optional)

Tasks Action

Create Tasks

To create a task, use theBtn Create Taskbutton in the main window of the module. The task creation window shown in Figure 4 will open. You will need to enter the name and description of the task. It is advisable to use a descriptive name, as this will be the name displayed in the list of available task. Click OK to create the task or CANCEL if you do not wish to proceed.

Create Task Window
Figure 4. Create task window

Once created, the task will appear in the list of available tasks within the application, here you can also search task by name as shown in Figure 5.

Group List
Figure 5. Group list

When selecting a task the main module window will display the information and buttons actions as shown in Figure 6.

TaskInformation
Figure 6. Task information

Script

In the script section shown in Figure 6, you can define your own scripts, which can range from custom inventory queries to the perform complex actions.

Information It is out of the scope of this document to teach how to code scripts, however, you can find more detail and examples in the scripts available in this repository.

Script Parameters

It is important to note that most scripts will require input parameters. These parameters can be easily added to the task so that the user can fill them in before executing the task. To manage the parameters, click on theBtn manage Parametersbutton. The parameter management window shown in Figure 7 will open, allowing you to create, edit, and delete parameters.

Manage Parameters Window
Figure 7. Manage parameters window

To create a parameter, use theBtn Create Taskbutton in the main parameter management window. The window to add a new parameter, shown in Figure 8, will open. Enter the name of the parameter to be used in the script and its value. Click OK to create it or Cancel if you decide not to proceed.

New Parameters Window
Figure 8. New parameters window

Once created, the parameter will be visible in the parameter management window, as shown in the example in Figure 8. You can edit its properties using theBtn Updatebutton or delete it with theBtn Delete Parameterbutton seen in Figure 9.

Parameter Example
Figure 9. Parameter example
Save And Execute Script

Once the script and its parameters have been created, as shown in the example in Figure 10, you can save the script changes using theBtn Savebutton seen in Figure 5.

Script Example
Figure 10. Basic example of script and parameters

Or use theBtn Executebutton seen in Figure 5 to save the script changes and execute your script.The execution result will be displayed in the popup window, si la ejecución fue exitosa el resaltado sera resaltado en color verde como se muestra en la Figura 11.

Script Execution Example
Figure 11. Script execution

If errors occur during the script execution, the result will be highlighted in red, as shown in Figure 12.

Fail Script Execution Example
Figure 12. Failed script execution
Commit On Execute

If you want the changes made by the script to be saved in the database after it is executed, enable CommitOnExecute by toggling the switch seen in Figure 6. from disabledDisable committo enabledEnable commit

Warning The changes made by tasks in the database can break things if your code is wrong. Ensure that the script execution was successful before enabling this feature. By default, CommitOnExecute is set to false.

Update Task Properties

To edit the properties of a task, use theBtn Updatebutton seen in Figure 6. The task update window shown in Figure 13 will open. Edit the desired properties and click OK to update them or CANCEL if you do not wish to proceed.

Update Task
Figure 13. Update task properties window

Delete Task

To delete a task, use theBtn Create Taskbutton seen in Figure 6. The confirmation window shown in Figure 14 will open. Click OK to delete it or Cancel if you decide not to proceed.

Delete Task
Figure 14. Delete task confirmation window

Schedule Task

It is possible to schedule task execution using the scheduling module, explained in detail in the Scheduling module section.