In Progress
Creating JobScheduler API Jobs using .NET
In addition to the programming languages natively supported by the JobScheduler API, JobScheduler can call .NET Objects with access on its API.
JobScheduler .NET API
The JobScheduler .NET API dlls are included in the lib\sos\com.sos-berlin.jobscheduler.engine.engine-taskserver-dotnet-<version>.jar file of a JobScheduler Windows Agent installation.
Extract lib\sos\com.sos-berlin.jobscheduler.engine.engine-taskserver-dotnet-<version>.jar to any location and find two dll files in the com\sos\scheduler\engine\taskserver\dotnet\dlls
subdirectory:
com.sos-berlin.engine.engine-job-api-dotnet.dll
jni4net.n-0.8.8.0.dll
.
Setting up a project in Visual Studio
- Create a new project of type "Class Library"
- Choose .NET Framework 4
- Add References:
- Add Reference
com.sos-berlin.engine.engine-job-api-dotnet.dll
- Add Reference
jni4net.n-0.8.8.0.dll
- Add Reference
- Create a Class to implement a JobScheduler job or a JobScheduler monitor
Job API
Implementing the job
JobScheduler will later try to find the .NET class as "namespace.classname".
Code for a simple c# job:
namespace JobSchedulerSamples { using sos.spooler; public class SampleJob : Job_impl { #region Public Methods public override void spooler_close() { this.spooler_log.info(".NET spooler_close"); } public override void spooler_exit() { this.spooler_log.info(".NET spooler_exit"); } public override bool spooler_init() { const string method = ".NET spooler_init"; this.spooler_log.info(method + ": spooler_task.id() = " + this.spooler_task.id()); var taskParams = this.spooler_task.@params(); if (taskParams != null) { var testParam = taskParams.value("test"); if (!string.IsNullOrEmpty(testParam)) { this.spooler_log.info(method + ": test param = " + testParam); } } return true; } public override void spooler_on_error() { this.spooler_log.info(".NET spooler_on_error"); } public override void spooler_on_success() { this.spooler_log.info(".NET spooler_on_success"); } public override bool spooler_open() { this.spooler_log.info(".NET spooler_open"); return true; } public override bool spooler_process() { this.spooler_log.info(".NET spooler_process"); return this.spooler_task.order() != null; } #endregion } }
Running the job
In JobScheduler the job for the above example is configured as follows:
<?xml version="1.0" encoding="ISO-8859-1"?> <job title="CSharp SampleJob" order="no" process_class="agent"> <params> <param name="test" value="12345" /> </params> <script language="dotnet" dotnet_class="JobSchedulerSamples.SampleJob" dll="dlls/JobSchedulerSamples.dll" /> <run_time /> </job>
Monitor API
Implementing the monitor
JobScheduler will later try to find the .NET class as "namespace.classname".
Code for a simple c# monitor:
namespace JobSchedulerSamples { using sos.spooler; public class SampleMonitor : Monitor_impl { #region Public Methods public override bool spooler_process_after(bool spoolerProcessResult) { this.spooler_log.info(".NET spooler_process_after"); return spoolerProcessResult; } public override bool spooler_process_before() { this.spooler_log.info(".NET spooler_process_before"); return true; } public override void spooler_task_after() { this.spooler_log.info(".NET spooler_task_after"); } public override bool spooler_task_before() { this.spooler_log.info(".NET spooler_task_before"); return true; } #endregion } }
Running the monitor
In JobScheduler the monitor for the above example is configured as follows:
<?xml version="1.0" encoding="ISO-8859-1"?> <job title="CSharp SampleMonitor" order="no" process_class="agent"> <params> </params> <script language="shell"><![CDATA[echo Hello, World]]></script> <monitor name="csharp_monitor" ordering="1"> <script language="dotnet" dotnet_class="JobSchedulerSamples.SampleMonitor" dll="dlls\JobSchedulerSamples.dll" /> </monitor> <run_time /> </job>
Samples
Download and extract JobSchedulerSamples.NET.zip
- Copy
dlls
folder to the agent working directory (agent_home) - Copy
dotnet_samples
folder to the master live directory (config/live)- Configure agent url in the
agent.process_class.xml
- Configure agent url in the
- Run samples