Background Processes are processes that are executed without the direct action of the user. Different rules can be set to schedule when the process is executed. This article discusses about the Openbravo infrastructure for Background Processes – how to create, define, schedule and monitor Background Processes.
Develop a DAL background process
Consider that this is a java class implementing the business logic and that we are demonstrating how a background process is developed. Use the new Data Access Layer which provides mid-tier POJOs through which we can manipulate database tables. If this method is used, your background java class must extend the DalBaseProcess class and implement the doExecute method that performs your task. As a side note: in this how-to we will show how a java process can be implemented as a background process. A java process can however also be called directly from the user interface and have a user interface which allows entering parameters.
Definition within the application dictionary
Background processes are defined within the Application Dictionary || Report and Process window. Use the System Administrator role to create a new record as indicated below in the diagram:
DAL based background process setup in the application dictionary
The following fields are vital for the definition of a background process:
- Module – your custom module that this new background process will belong to; note that this will consequently indicate the location on the hard drive and the package it must belong to
- Search Key – unique identifier of the process; a good practice is to use the class name
- Name – a user friendly name of the process
- UI Pattern – should be set to Manual since Openbravo ERP does not need to generate any UI windows
- Background – indicates that this process is a background process which consequently also displays the Java Class Name field
- Java Class Name – the full specification of the class name including the package (this package must follow the package structure of your module specified above)
Defining a Background Process
Background Processes are defined in the window General Setup || Process Scheduling || Process Request. Firstly, in the field Process, select the process to execute and in the field Timing, time to execute.
Depending on Timing selected, more fields are required to be defined.
The timing frequency is of three types:
This timing option will execute the Background Process the time at the moment the button to schedule the process is pressed. After it has been scheduled, it can be rescheduled as many times as needed.
This option is very similar to executing a process from a menu option. The difference is that when scheduling a Run Immediately Background Process, there will not be any pop-up that indicates when the execution finished and instead it will register its execution in the Process Monitor.
This option is similar to the previous option. In this case the Background Process will be executed only one time in one moment in the future.
The moment when the Background Process will be executed is defined in the fields Start Date and End Date.
This is the most versatile option that allows executing a Background Process periodically. These are the fields used to define the schedule plan of a Background Process:
- Start Date and Start Time: Defines the moment when the schedule plan for this Background Process will start
- Frequency: Defines the frequency to execute the Background Process. It can be Every n seconds, Every n minutes, Hourly, Daily, Weekly, Monthly, or Cron expression. Depending on the option selected you can define the specific details for each frequency option
Finish Date and Finish Time: These fields can be defined only when the option Finished is selected. And it defines when to stop the schedule plan for this Background Process
Grid view of Background process defined.
Schedule and Unschedule a Background Process
After the Background Process has been completely defined it can be scheduled pressing the button Schedule Process. When a process is scheduled, it will be executed according to the Timing options selected, and every execution will be registered in the Process Monitor.
To stop future executions of a Background Process select the option Unschedule Process. After a Background Process has been unscheduled it can be scheduled again in any moment pressing the button Reschedule Process.
Sample Background process
Monitoring executions of Background Processes
All the executions of Background Processes can be monitored in General Setup || Process Scheduling || Process Monitor.
Process Monitor Window
In this window there is one entry for each Background Process execution and the information of each execution. The most important fields are:
- Process: The Process executed
- Start Time, End Time and Duration: When the execution started, when finished and the time it took to complete
- Status: The final result of the execution of the Process
- Process Log: The information logged during the execution of the Process. For example if the Status of the execution is Error, here in the Process Log the reason for the error can be detected