Table of Contents

Class NativeJob

Namespace
Quartz.Jobs
Assembly
Quartz.Jobs.dll

Built in job for executing native executables in a separate process.

public class NativeJob : IJob
Inheritance
NativeJob
Implements
Inherited Members

Remarks

What is run is configured through the job data keys below. NativeJobOptions names them all, and UsingNativeJobOptions<TConfigurator>(TConfigurator, NativeJobOptions) writes them, so the settings can be given as a value rather than as string keys; the keys stay the persisted form either way.

IJobDetail job = JobBuilder.Create<NativeJob>() .WithIdentity("dumbJob") .UsingNativeJobOptions(new NativeJobOptions { Command = "echo \"hi\" >> foobar.txt" }) .Build();
ITrigger trigger = TriggerBuilder.Create()
    .WithIdentity("dumbTrigger")
    .WithSimpleSchedule(x => x.WithInterval(TimeSpan.FromSeconds(5)).RepeatForever())
    .Build();

await scheduler.ScheduleJob(job, trigger);

If PropertyWaitForProcess is true, then the integer exit value of the process will be saved as the job execution result in the JobExecutionContext.

Constructors

NativeJob()

Initializes a new instance of the NativeJob class.

public NativeJob()

Fields

PropertyCommand

Required parameter that specifies the name of the command (executable) to be ran.

public const string PropertyCommand = "command"

Field Value

string

PropertyConsumeStreams

Optional parameter (value should be 'true' or 'false') that specifies whether the spawned process's stdout and stderr streams should be consumed. If the process creates output, it is possible that it might 'hang' if the streams are not consumed.

Defaults to false.

public const string PropertyConsumeStreams = "consumeStreams"

Field Value

string

PropertyParameters

Optional parameter that specifies the parameters to be passed to the executed command.

public const string PropertyParameters = "parameters"

Field Value

string

PropertyWaitForProcess

Optional parameter (value should be 'true' or 'false') that specifies whether the job should wait for the execution of the native process to complete before it completes.

Defaults to true.

public const string PropertyWaitForProcess = "waitForProcess"

Field Value

string

PropertyWorkingDirectory

Optional parameter that specifies the working directory to be used by the executed command.

public const string PropertyWorkingDirectory = "workingDirectory"

Field Value

string

Methods

Execute(IJobExecutionContext, CancellationToken)

Called by the IScheduler when a ITrigger fires that is associated with the IJob.

The implementation may wish to set a result object on the JobExecutionContext before this method exits. The result itself is meaningless to Quartz, but may be informative to IJobListeners or ITriggerListeners that are watching the job's execution.

public virtual ValueTask Execute(IJobExecutionContext context, CancellationToken cancellationToken = default)

Parameters

context IJobExecutionContext

The firing this job is running for, whose merged job data names the command.

cancellationToken CancellationToken

The cancellation instruction.

Returns

ValueTask