Skip to content

api jobs

Ayhan Rashidov edited this page Sep 5, 2022 · 2 revisions

$.jobs API

Represents an XS scheduled job.

Reference

Scheduled jobs define recurring tasks that run in the background. The JavaScript API $.jobs allows developers to add and remove schedules from such jobs.

SAP Help

https://help.sap.com/doc/3de842783af24336b6305a3c0223a369/2.0.03/en-US/$.jobs.Job.html

Module

https://github.com/codbex/codbex-kronos/tree/main/modules/api/api-xsjs/src/main/resources/META-INF/dirigible/kronos/jobs

Sample Usage

Create a definition.xsjob file:

{
	"description": "My Job configuration",
	"action": "xsjob_demo:handler.xsjslib::writeInDB",
	"schedules": [
		{
			"description": "Execute every 5 seconds",
			"xscron": "* * * * * * */5",
			"parameter": {
			}
		}
	]
}

Create a handler.xsjslib file:

function writeInDB() {
    var connection;
    try {
        connection = $.db.getConnection();
        
        var insertStatement = connection.prepareStatement("INSERT INTO XSJOB_DEMO (EXECUTED_AT) VALUES (CURRENT_TIMESTAMP)");
        insertStatement.executeUpdate();
        insertStatement.close();
    } catch(e) {
        connection.rollback();
        console.log("Transaction was rolled back: " + e.message);
    } finally {
       connection.close();
    }
}

And now, to use the API, create a .xsjs file:

var job = new $.jobs.Job({ uri: "xsjob_demo/definition.xsjob" });

// execute the job for 60 seconds, starting from now
job.configure({ status: true, start_time: new Date(), end_time: new Date(Date.now() + 60000) });

Coverage

Methods Description Status
activate() Activates an XS Job that has already been configured.
configure(config) Configure an XS Job. The function provides additional means to programmatically configure an XS Job. Configuration must be done prior to activate/deactivate an XS Job.
deactivate() Deactivates an XS Job that has already been configured.
getConfiguration() Retrieve current configuration of an XS Job as object.

Unit Tests ❌

Integration Tests ❌

Wiki icons legend

✅ - Feature implemented and working as supposed.
⚠️ - Feature partially implemented and needs to be finished.
❌ - Feature not implemented yet.

Clone this wiki locally