Create Single JOB Package

In this section you will learn how to create a DMS scheduled job starting from a template project. First of all download Samples from DMSContainer Repository

DMSContainer Repository Samples

Clone project dms_job_quickstart_only_scheduled_job under dms_jobs_quickstart folder.

This project is going to be used as a template to create your job. Follow these steps:

  1. Open the cloned project in Delphi IDE

  2. Rename project as “dms_job_<yourjobname>”

  3. Rename unit Jobs.QuickStart2.Job as “Job.<yourjobname>.job” rename job

Create Job Class

Rename Class TQuickStart2Job as “T<yourjobname>Job” rename job

Write your own job code in DoExecute method

Job Configuration File

Optionally you can provide your job with custom configuration stored inside a config file. Job config can be stored in conf folder following this pattern:

job.<yourjobname>.config.json

It must contain a JSONObject with job configuration. Here it is, as example, jobemail configuration file:

{
  "max_retry_count": "5",
  "default_smtp_ssl_version":"TLSv1",
  "max_emails_count": 5
}

To access job configuration you can use TConfigurableJob jobs, JobConfig property:

lMaxRetries := lMaxRetries := JobConfig ['max_retry_count'].ToInteger;
if lMaxRetries < 1 then
begin
  raise EDMSConfigException.Create('max_retry_count', JobName);
end;

or using GetConfiguration method:

GetConfiguration(GetConfigFolder, JobName);

Compile Package

Check whether DMS_HOME variable is setted and that points to your DMS installation, in tools\Options\Environment Variables: rename job

Build the package. You will find the newly created bpl under DMS installation in jobspackage folder as setted in Project Compiler Options: rename job

Setting up Configuration

Add Job configuration in jobsmanager.json file under Conf folder. Please change Jobname and jobclass with the right name:

  • jobname: it is a description name of your job
  • jobclass: it is the fully qualified job class name.
{
  "enabled": true,
  "jobname": "your job name",
  "schedule": "* * * * * *",
  "jobtype":"class",
  "jobclass":"Jobs.<yourjobname>.Job.T<yourjobname>Job"
}

Scheduling your job

To correctly schedule your job please follow configuration page the scheduling syntax paragraph.

Restart your DMS Service

See also