Batch Processors

Overview

A headless client in Servoy is a client session that runs on the server without a user interface. It does not have a visible interface for end users but can perform tasks and execute scripts programmatically. The headless client can be used to run background processes, automate tasks, and perform operations without requiring user interaction. It is typically managed and controlled using the headless API, allowing developers to queue methods, receive callbacks, and monitor the status of tasks running in the headless client session.

A batch processor in Servoy is a term used to describe a headless client session that is configured to start when the entire application server starts. It is designed to run a job on a schedule without the need for user interaction. The batch processor can be set up with specific startup arguments, cron timings, and other parameters to define its behavior. This allows for automated tasks to be executed at regular intervals or on a predefined schedule. The batch processor is stored in the server properties file, ensuring that the solution starts in a headless client every time the server starts up. It is particularly useful for tasks that need to be completely automated without any user intervention, such as running scheduled jobs or recurring processes.

Configured Servoy Batch processors start automatically when the Servoy Application Server is started. The Batch Processor can either execute business logic periodically or can be triggered by an external process.

Here is the webinar section that covers Batch Processors:

Using the onOpen event of the solution to execute code

In the context of batch processing in Servoy, the onOpen solution event onSolutionOpen method can be utilized to trigger actions when the solution containing the batch processor is opened. This onSolutionOpen method hooked to the onOpen event is particularly useful for initializing the batch processor, setting up any necessary configurations, and starting the scheduled job that the batch processor will execute.

Here are some common tasks that can be performed in the onSolutionOpen method for a batch processor:

  • Configuration Setup: Set up any required configurations for the batch processor, such as defining cron timings, specifying job parameters, or configuring any necessary settings.

  • Initialization: Initialize variables, set default values, and prepare the batch processor for execution.

  • Scheduling Jobs: Use the onSolutionOpen method to schedule the job that the batch processor will run at specified intervals or on a predefined schedule, by combining it with the scheduler plugin.

  • Logging: Log messages or events related to the batch processor initialization and setup for monitoring and debugging purposes.

By using the onSolutionOpen method effectively in the context of batch processing, you can ensure that the batch processor is properly configured and ready to execute scheduled tasks as intended.

Example:

/**
 *
 * @param {String} arg startup argument part of the deeplink url with which the Client was started
 * @param {Object<Array<String>|String>} queryParams all query parameters of the deeplink url with which the Client was started, key>string if there was one value else key>Array<String>
 *
 * @properties={typeid:24,uuid:"FCB8FDF5-3A8F-4767-98C6-5CFBD20812F7"}
 */
function onSolutionOpen(arg, queryParams) {
	application.output('Batch Processor loaded with startup args' + arg, LOGGINGLEVEL.INFO);
    
	plugins.scheduler.addCronJob('myJob',arg,runJob)
}


/**
 * @properties={typeid:24,uuid:"9FC1E99C-518A-408F-952E-82493DF8F846"}
 */
function runJob(){
	
	application.output('I am doing something', LOGGINGLEVEL.INFO);
}

Add a batch processor (via admin page)

The Batch Processor properties' configurations will be recorded in servoy.properties file, so it can also be done purely by configuration. Once a Batch Processor is configured, it's stored in the servoy.properties file, so every time the server comes up the solution will start in a headless client, the onSolutionOpen method is fired and then in that method is scheduled the task.

Create new batch processor client:

Here are the steps to create new batch processor client:

  1. Go to Servoy Admin Page and enter Batch processors section

  2. Pick a solution from that you've imported

  3. Give it some startup arguments, for example cron timings

  4. Give some credentials to login (username and password), if required

  5. Click the Add button and the Batch process list will appear

Once a batch processor is created, it will appear in the Batch process list.

Starting a Batch Processor

In order to start a batch processor, find it in the list and click the Start button of its Status property.

Stopping a Batch Processor

In order to start a batch processor, find it in the list and click the Stop button of its Status property.

Disabling a Batch Processor

In order to start a batch processor, find it in the list and click the Disable button of its Enablement property.

Disabling all Batch Processors

By default, batch processors are enabled on server startup. In order to disable all batch processors, click on the Disable button found on top of the Batch processors section of Servoy Admin Page.

Removing a Batch Processor

In order to start a batch processor, find it in the list and click the Remove button of its Solution property.

Last updated