In this section we are going to create a simple beeper JOB, then we’ll add a JSON-RPC interface and will test it with a python script.
<DMS_HOME>\SDK
folder, add the following DCPs among the Requires packages section:
dmsRT
dmvcframeworkRT.dcp
loggerproRT.dcp
LockBoxDR
Package Output Directory
to point to the folder jobspackage
of your DMSContainer instance.dms_job_beeper.dproj
add a new unit called Jobs.Beeper.Job.pas
.Write the following code into the unit Jobs.Beeper.Job.pas
unit Jobs.Beeper.Job;
interface
uses DMSCommonsU, DMSCustomJob, DMSLoggingU;
type
TBeepJob = class(TCustomJob)
protected
procedure DoExecute; override;
end;
implementation
uses
WinApi.Windows, System.SysUtils;
{ TBeepJob }
procedure TBeepJob.DoExecute;
begin
Log.Info('Hello! I''m going to play something amazing!!', JobName);
WinApi.Windows.Beep(440, 80);
end;
initialization
Randomize;
TBeepJob.ClassName;
end.
dms_job_beeper.bpl
is present into the folder <DMS_HOME>\jobspackage
NOTE: At the startup DMSContainer loads all the packages inside the folder
<DMS_HOME>\jobspackage
whom name starts withdms_job_
. Using a different name, the package will not be loaded.
<DMS_HOME>\conf\jobsmanager.json
file and add a new JSON object, as the last of the jobs
array, to configure the new beeper
job.Now, your jobsmanager.json
file should looks like the following
{
"jobs":[
{
"enabled": true,
"jobname": "email",
"schedule": "* * * * * *",
"jobtype":"class",
"jobclass":"Jobs.Email.Job.TJobEmail",
"rpcclass":"Jobs.Email.RPC.TEmailRPC",
"rpcuri":"/emailrpc"
},
# other jobs here...
{
"enabled": true,
"jobname": "beeper",
"schedule": "* * * * * *",
"jobtype":"class",
"jobclass":"Jobs.Beeper.Job.TBeepJob"
}
]
}
RUN_DEBUG.BAT
batch file.dms_00.beeper.log
If DMSContainer doesn’t start, check the main log file names
dms_00.main.log
However, working without a debugger is not a viable solution nowadays, so let’s configure the Delphi IDE to help in the development of DMSContainer Jobs.
If while working with small package a debugger can be a nice addition but not a requirement, if the packages you are working on gets bigger, you definitively need a debugger. The Delphi debugger is one of the best on the market, so using DMSContainer you can use it and enjoy a pleasant development experience.
Follow these steps to instruct DMSContainer and Delphi to work nicely together.
dms_job_beeper.dproj
project in the IDE.Project->Options
and in the opening window, select the node Debugger
.Host Application
write the full path of the DMSContainerService.exe
executable (default is <DMS_HOME>\DMSContainerService.exe
).Parameters
write /console
.Debugger->Environment Block
and add the following variable in the box “User System Override”:
DMS_HOME
with value C:\bitTimeProfessionals\DMSContainer_3_1_0
(or the folder where you decided to install DMSContainer).DMSContainerService
as usual from the Windows Service Console.WARNING: If for some reason you want to run DMSContainer as console also outside the Delphi IDE, you can still use the /console
switch opening a command prompt and issuing the following commands (remember to stop the DMSContainerService.exe from the Windows Services).
set DMS_HOME=C:\bitTimeProfessionals\DMSContainer_3_1_0
DMSContainerService.exe /console
If it works for you, you can also use the RUN_DEBUG.BAT file to run DMSContainer as console application in debug mode.
In this section we’ll add a JSON-RPC interface to the beeper job.
dms_job_beeper.dproj
(or create a new package following the instructions of the previous paragraphs)Add a new unit called Jobs.Calculator.RPC.pas
. The following code is a a simple, but working, RPC class which can be remotely accessed through the JSON-RPC interface
unit Jobs.Calculator.RPC;
interface
uses
DMSCustomRPC;
type
TCalculatorRPC = class(TCustomRPC)
public
function Sum(const A, B: Integer): Integer;
end;
implementation
{ TCalculatorRPC }
function TCalculatorRPC.Sum(const A, B: Integer): Integer;
begin
Result := A + B;
end;
end.
dms_job_beeper.bpl
is present into the folder <DMS_HOME>\jobpackages
jobsmanager.json
file and add a new JSON object to configure our new job.Your jobsmanager.json
file should looks like the following
{
"jobs":[
{
"enabled": true,
"jobname": "email",
"schedule": "* * * * * *",
"jobtype":"class",
"jobclass":"Jobs.Email.Job.TJobEmail",
"rpcclass":"Jobs.Email.RPC.TEmailRPC",
"rpcuri":"/emailrpc"
},
{
"enabled": true,
"jobname": "beeper",
"schedule": "* * * * * *",
"jobtype":"class",
"jobclass":"Jobs.Beeper.Job.TBeepJob",
"rpcclass":"Jobs.Calculator.RPC.TCalculatorRPC",
"rpcuri":"/beeperrpc"
}
]
}
Now you first Class Job is up and running.. it’s time to test it!