In Progress
- This article applies to JobScheduler releases from 1.11.4
- Starting from JobScheduler Release 1.10.5 native support for PowerShell is available
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 is included in the lib\sos\com.sos-berlin.jobscheduler.engine.engine-taskserver-dotnet-<version>.jar of a JobScheduler Windows Agent installation.
Extract lib\sos\com.sos-berlin.jobscheduler.engine.engine-taskserver-dotnet-<version>.jar to any location:
- com\sos\scheduler\engine\taskserver\dotnet\dlls
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 or higher
- 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-1.11.x"> <params> <param name="test" value="12345" /> </params> <script language="dotnet" dotnet_class="JobSchedulerSamples.SampleJob" dll="<path to dll>\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 } }