Class FileScanJob
Inspects a file and compares whether its "last modified date" has changed since the last time it was inspected. If the file has been updated, the job invokes a "call-back" method on an identified IFileScanListener that can be found in the SchedulerContext.
public class FileScanJob : IJob
- Inheritance
-
FileScanJob
- Implements
- Inherited Members
Remarks
What is watched is configured through the job data keys below. FileScanOptions names them all, and UsingFileScanOptions<TConfigurator>(TConfigurator, FileScanOptions) writes them, so the settings can be given as a value rather than as string keys; the keys stay the persisted form either way.
Constructors
FileScanJob(TimeProvider?)
Initializes a new instance of the FileScanJob class.
public FileScanJob(TimeProvider? timeProvider = null)
Parameters
timeProviderTimeProviderThe clock deciding how recently the file must have been written to still count as being written to. null takes System.
Fields
FileName
JobDataMap key with which to specify the name of the file to monitor.
public const string FileName = "FILE_NAME"
Field Value
FileScanListenerName
JobDataMap key with which to specify the IFileScanListener to be notified when the file contents change.
public const string FileScanListenerName = "FILE_SCAN_LISTENER_NAME"
Field Value
MinimumUpdateAge
JobDataMap key with which to specify a long value that represents the minimum number of milliseconds that must have past since the file's last modified time in order to consider the file new/altered. This is necessary because another process may still be in the middle of writing to the file when the scan occurs, and the file may therefore not yet be ready for processing.
If this parameter is not specified, a default value of 5000 (five seconds) will be used.
MinimumUpdateAge says the same thing as a TimeSpan.
public const string MinimumUpdateAge = "MINIMUM_UPDATE_AGE"
Field Value
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
contextIJobExecutionContextThe execution context.
cancellationTokenCancellationTokenThe cancellation instruction.
Returns
- See Also
GetLastModifiedTime(string)
Reads the time the file was last written to.
protected virtual DateTimeOffset? GetLastModifiedTime(string fileName)
Parameters
fileNamestringName of the file.
Returns
- DateTimeOffset?
The last write time, or null when nothing exists at that path.