Class JobExecutionContextInputExtensions
- Namespace
- Quartz
- Assembly
- Quartz.dll
Reads the input a job was scheduled with.
public static class JobExecutionContextInputExtensions
- Inheritance
-
JobExecutionContextInputExtensions
- Inherited Members
Remarks
An extension rather than a member of IJobExecutionContext, so that every hand-written context — a test double, an adapter — keeps compiling. An IJob<TInput> does not need this: its input arrives as a parameter.
Methods
GetInput<TInput>(IJobExecutionContext)
The input this firing carries, or default when it carries none.
public static TInput? GetInput<TInput>(this IJobExecutionContext context)
Parameters
contextIJobExecutionContextThe firing to read the input of.
Returns
- TInput
Type Parameters
TInputThe type the input was scheduled as.
Remarks
The trigger's input wins over the job's, which is what MergedJobDataMap means everywhere else.
TInput is the type the payload is read back as, so a job reading its own
input names the same type the scheduling side passed. An input stored as JSON by a different type
comes back as whatever this type can make of that JSON.
Exceptions
- SchedulerException
The input is stored but cannot be read: the context was built without an IJobInputSerializer, or the stored value is neither a payload nor a
TInput.
TryGetInput<TInput>(IJobExecutionContext, out TInput?)
The input this firing carries, reporting whether it carried one at all.
public static bool TryGetInput<TInput>(this IJobExecutionContext context, out TInput? input)
Parameters
contextIJobExecutionContextThe firing to read the input of.
inputTInputThe input this firing carries, or default when it carries none.
Returns
Type Parameters
TInputThe type the input was scheduled as.
Remarks
What GetInput<TInput>(IJobExecutionContext) cannot say: a payload that deserialized to null and no payload at all are the same answer there, and different here.
The reason it exists is an upgrade. A 3.x application converting a job to IJob<TInput> over a store that already holds its triggers finds those triggers carrying the old shape — the payload spread over flat JobDataMap keys — and nothing under JobInput; an IJob<TInput> fails such a firing by name rather than running it with a default payload. A job that has to serve both shapes for a while stays an IJob and reads them apart:
public ValueTask Execute(IJobExecutionContext context, CancellationToken cancellationToken = default)
{
SendInvoice invoice = context.TryGetInput(out SendInvoice? typed) && typed is not null
? typed
: new SendInvoice(context.MergedJobDataMap.GetString("CustomerId")!, context.MergedJobDataMap.GetDecimal("Amount"));
return Send(invoice, cancellationToken);
}
It is still an error for a stored input to be unreadable: a value that is present but neither a
TInput nor a payload the serializer can read throws, because corruption
is not compatibility. Only absence is answered with false.
Exceptions
- SchedulerException
The input is stored but cannot be read: the context was built without an IJobInputSerializer, or the stored value is neither a payload nor a
TInput.