Easy Extension Framework v0.5 Help

Easy Cron Job

The EasyCronJob feature is an enhancement on top of standard CronJob feature. It lets you create new cronjob at runtime with JSON parameter, so you do not need to override CronJob model.

Creating an EasyCronJob

All EasyCronJobs use the same default type which is EasyCronJobModel. The EasyCronJobModel is an extended class of CronJobModel and comes with a special configuration field. In this field, you need to define your cronjob configuration as a JSON object.

{ "myTextParameter": "Hello World", "myNumberParameter": 100, "myBooleanParameter": true, "mayListParameter": [ { "name": "childParameter1", "value": "Hello from Child 1" }, { "name": "childParameter2", "value": "Hello from Child 2" } ] }

So unlike standard CronJob feature, you do not extend CronJobModel for your configuration requirements. You only need to provide your required cronjob configuration as a JSON object to EasyCronJobModel.configuration. Please note that the EasyCronJobModel.configuration only allows valid JSON objects (not JSON array) or empty value.

1. Create a Groovy class which extends EasyJobPerformable

In your Easy extension, create a Groovy class which extends EasyJobPerformable class. EasyJobPerformable itself is an extended class of standard AbstractJobPerformable. Your JSON text configuration inside EasyCronJobModel.configuration field will be converted into a Map object by the abstract EasyJobPerformable class and will be passed to the performInternal method along with the EasyCronJobModel.

package com.sap.cx.boosters.easycronjobsample.cronjob import org.slf4j.Logger import org.slf4j.LoggerFactory import com.sap.cx.boosters.easy.core.cronjob.EasyJobPerformable import com.sap.cx.boosters.easy.core.model.`EasyCronJobModel` import de.hybris.platform.cronjob.enums.CronJobResult import de.hybris.platform.cronjob.enums.CronJobStatus import de.hybris.platform.servicelayer.cronjob.PerformResult import de.hybris.platform.servicelayer.user.UserService class SampleEasyCronJobPerformable extends EasyJobPerformable { private static final Logger LOG = LoggerFactory.getLogger('samplecronjob') @Resources UserService userService @Override PerformResult performInternal(`EasyCronJobModel` cronJob, Map configuration) { LOG.info("myTextParameter: ${configuration.myTextParameter}") LOG.info("myNumberParameter: ${configuration.myNumberParameter}") LOG.info("myBooleanParameter: ${configuration.myBooleanParameter}") configuration.mayListParameter.each { childParam -> LOG.info("parameter: ${childParam.name} / value: ${childParam.value}") } // You can use clearAbortRequestedIfNeeded to check if abort is requested if(clearAbortRequestedIfNeeded(cronJob)) { return new PerformResult(CronJobResult.FAILURE, CronJobStatus.ABORTED) } // You can use following services that come along with EasyJobPerformable: // 1. modelService // 2. sessionService // 3. flexibleSearchService def count = flexibleSearchService.search('SELECT {pk} FROM {Job} WHERE {pk} = ?jobPk', ['jobPk': cronJob.getJob()]).getCount() LOG.info("Flexible Search Result Count: ${count}") // Or you can wire and use other services that you need LOG.info("Checking if current session user '${cronJob.getSessionUser().getUid()}' is an Admin user: ${userService.isAdmin(cronJob.getSessionUser())}") return new PerformResult(CronJobResult.SUCCESS, CronJobStatus.FINISHED) } }

You can use all standard features of a JobPerformable with EasyJobPerformable:

  • Return CronJob results and statuses

  • Create abortable CronJobs

  • Wire and use Spring beans (services)

  • Use Logging

2. Define your EasyCronJobPerformable bean inside EasyBeans.groovy

In your Easy extension, define EasyCronJobPerformable in EasyBeans.groovy file. Since we are extending EasyJobPerformable, the parent bean should be set to easyJobPerformable.

import com.sap.cx.boosters.easycronjobsample.cronjob.SampleEasyCronJobPerformable logger.info "[${extension.id}] registering Spring beans for core context" easyCoreBeans { sampleEasyCronJobPerformable(SampleEasyCronJobPerformable) { it.parent = ref('easyJobPerformable') } } logger.info "[${extension.id}] registering Spring beans for core context"}

The EasyBeanPerformable bean should be defined only as a . That is why we are checking the application name because Core Context has no name.

3. Create your EasyCronJob items using Easy ImpEx

Create a ServiceLayer item for your EasyCronJobPerformable and a CronJob item for your EasyCronJob. You can create these items within your Easy extension using Easy ImpEx.

EasyCronJob folder structure

Under impex/install folder, create an ImpEx file

INSERT_UPDATE ServicelayerJob;code[unique=true];springId[unique=true]; ;sampleEasyCronJob;sampleEasyCronJobPerformable; INSERT_UPDATE EasyCronJob;code[unique=true];active;job(code);sessionUser(uid);sessionLanguage(isocode);sessionCurrency(isocode);configuration; ;sampleEasyCronJob;true;sampleEasyCronJob;admin;en;GBP;"{ ""myTextParameter"": ""Hello World"", ""myNumberParameter"": 100, ""myBooleanParameter"": true, ""mayListParameter"": [ { ""name"": ""childParameter1"", ""value"": ""Hello from Child 1"" }, { ""name"": ""childParameter2"", ""value"": ""Hello from Child 2"" } ] }"

You can define a CronJob trigger if you need one.

Also, it is a good practice to create an uninstallation ImpEx file

REMOVE ServicelayerJob;code[unique=true] ;sampleEasyCronJob REMOVE EasyCronJob;code[unique=true] ;sampleEasyCronJob

4. Set your EasyCronJob Java properties using Easy properties

You can set the required Java properties (e.g. logging) of your EasyCronJob using Easy properties (the easy.properties file in your Easy extension)

log4j2.logger.remotearchive.name=samplecronjob log4j2.logger.remotearchive.level=INFO

Running your EasyCronJob

Once you have installed your Easy extension that contains your EasyCronJob, you are ready to go.

From Backoffice > Easy > Easy Core > CronJobs link you can view, create, modify, delete or start your EasyCronJobs.

EasyCronJob backoffice

EasyCronJob editor comes with "EasyCronJob Configuration" tab that is fully dedicated for your cronjob configuration which needs to be a JSON object

EasyCronJob backoffice configuration

EasyCronJobs are standard CronJobs and you can still use standard Backoffice > System > Background Processes > CronJobs link to view, create, modify, delete or start your EasyCronJobs.

EasyCronJob backoffice standard
Last modified: 18 August 2025