I have defined a job and trigger in the an MSSQL database but cannot get the job to load or trigger to fire. I’m just wondering if someone can guide me towards the resolution to this, I’m sure I must be doing something wrong, but just cannot spot it. I have been all over the Quartz.NET documentation but may be misunderstanding some settings.
Any and all help greatly appreciated.
You can see some of the output from the start up below, and you can see the message about “adding 0 job, 0 triggers”
Using job store 'Quartz.Impl.AdoJobStore.JobStoreTX', supports persistence: True, clustered: True
{"@t":"2024-07-08T14:10:24.3246282Z","@mt":"Using job store 'Quartz.Impl.AdoJobStore.JobStoreTX', supports persistence: True, clustered: True","SourceContext":"Quartz.Impl.StdSchedulerFactory","SFTPService":"SFTPService"}
{"@t":"2024-07-08T14:10:24.3328792Z","@mt":"Adding 0 jobs, 0 triggers.","SourceContext":"Quartz.ContainerConfigurationProcessor","SFTPService":"SFTPService"}
Below is the startup code I have implemented to initialise Quartz, it’s running in a C# Console Application.
I have all configuration in the startup and am not using any settings in the app settings file.
//-------------------------------------------------------------------------
// Setup Quartz the timer scheduling library
//-------------------------------------------------------------------------
services.AddQuartzHostedService(opt =>
{
opt.WaitForJobsToComplete = true;
});
services.AddQuartz(q=>
{
q.UsePersistentStore(s =>
{
s.UseProperties = true;
s.UseNewtonsoftJsonSerializer();
s.UseSqlServer(sqlServer =>
{
sqlServer.ConnectionString = configuration.GetConnectionString("Quartz") ?? throw new ArgumentNullException("Quartz connection string");
sqlServer.TablePrefix = "QRTZ_";
});
s.UseClustering(c =>
{
c.CheckinInterval = TimeSpan.FromSeconds(10);
c.CheckinMisfireThreshold = TimeSpan.FromSeconds(20);
});
});
});
I have created some jobs in the database using the following scripts.
INSERT INTO QRTZ_JOB_DETAILS
(SCHED_NAME, JOB_NAME, JOB_GROUP, JOB_CLASS_NAME, IS_DURABLE, IS_NONCONCURRENT, IS_UPDATE_DATA, REQUESTS_RECOVERY, JOB_DATA)
VALUES
('SFTPService', 'SFTPDownloadJobName', 'SFTPJobGroup', 'MyCompany.SFTP.WorkerLibrary.SFTPDownloadJob, Codec.SFTP.WorkerLibrary', 1, 0, 0, 0, NULL);
INSERT INTO QRTZ_TRIGGERS
(SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP, JOB_NAME, JOB_GROUP, DESCRIPTION, NEXT_FIRE_TIME, PREV_FIRE_TIME, PRIORITY, TRIGGER_STATE, TRIGGER_TYPE, START_TIME, END_TIME, CALENDAR_NAME, MISFIRE_INSTR, JOB_DATA)
VALUES
('SFTPService', 'FrequentTriggerName', 'FrequentTriggerGroup', 'SFTPDownloadJobName', 'SFTPJobGroup', 'Fires every 20 seconds', NULL, NULL, 5, 'WAITING', 'CRON', DATEDIFF(SECOND, '1970-01-01', GETDATE()), NULL, NULL, 0, NULL);
INSERT INTO QRTZ_CRON_TRIGGERS
(SCHED_NAME, TRIGGER_NAME, TRIGGER_GROUP, CRON_EXPRESSION, TIME_ZONE_ID)
VALUES
('SFTPService', 'FrequentTriggerName', 'FrequentTriggerGroup', '0/20 * * * * ?', NULL);
DECLARE @jsonData NVARCHAR(MAX) = '{
"SftpHostName": "eu-central-1.sftpcloud.io",
"SftpPortNumber": "22",
"SftpUserName": "*********************",
"SftpPassword": "***********************",
"SftpRemoteDirectory": "/",
"SftpLocalDirectory": "",
"SftpFileNameOrPattern": "test.txt"
}';
DECLARE @jobData VARBINARY(MAX) = CONVERT(VARBINARY(MAX), @jsonData);
UPDATE QRTZ_TRIGGERS
SET JOB_DATA = @jobData
WHERE SCHED_NAME = 'SFTPService' AND TRIGGER_NAME = 'FrequentTriggerName' AND TRIGGER_GROUP = 'FrequentTriggerGroup';