Importing CronJob Instances Using ImpEx
Using ImpEx for creating instances of CronJob is useful if you want to define it declaratively, and not by creating code that must be compiled and deployed. This is worth applying especially for a system set up in combination with ImpEx Import for Essential and Project Data, as the data setup is often adjusted.
The tutorial presumes that you have already created MyJobPerformable and configured it as a Spring bean, as described in the HelloWorldCronJob Tutorial.
Update the system to automatically create the instance of ServicelayerJob related to defined myJobPerformable bean from Spring context.
Importing CronJobModel Instance
Create a cron job by importing an instance of HelloWorldCronJob type and reference it to the JobPerformable instance:
INSERT_UPDATE HelloWorldCronJob;code[unique=true];job(code);message;sessionLanguage(isocode); ;myHelloWorldServicelayerCronJob;myJobPerformable;greeting.key;en;
This example creates an instance of HelloWorldCronJobModel with an assigned ServicelayerJob instance, and some custom localized message key.
Creating Trigger
If you wish to start your cron job automatically, you need to define a trigger:
INSERT_UPDATE Trigger; cronJob(code)[unique=true]; cronExpression ; myHelloWorldServicelayerCronJob; 0 30 10-11 ? * WED,FRI
This ImpEx script creates an instance of Trigger assigned to myHelloWorldServicelayerCronJob and a cron expression that causes the trigger to start the cron job at 10:30, 11:30, every Wednesday and Friday.
Saving SessionContext Attributes During Import
When importing cron jobs through ImpEx, the system adds additional attributes needed for import purposes to SessionContext. All new cron jobs that are created receive all SessionContext attributes as sessionContextValues. To prevent sessionContextValues from holding redundant attributes that are required only during import, use the following property with a list of attributes that you don't want to save in new cron jobs' sessionContextAttributes:cronjob.ctx.filtered.attributes.in.impex.import.mode=disableRestrictions,disableRestrictionGroupInheritance,use.fast.algorithms,import.mode,disable.attribute.check,disable.interceptor.beans,disable.interceptor.types,disable.UniqueAttributesValidator.for.types,currentCronJob,currentJob,core.types.creation.initial,save.from.service.layer,ctx.enable.fs.on.read-replica,impex.creation
Use comma without whitespace as a delimiter. Attributes are case-sensitive. By default, the following attributes are included as the value of this property:
-
disableRestrictions,
-
disableRestrictionGroupInheritance,
-
use.fast.algorithms,
-
import.mode,
-
disable.attribute.check,
-
disable.interceptor.beans,
-
disable.interceptor.types,
-
disable.UniqueAttributesValidator.for.types,
-
currentCronJob,
-
currentJob,
-
core.types.creation.initial,
-
save.from.service.layer,
-
ctx.enable.fs.on.read-replica,
-
impex.creation.