09-12-2022

This commit is contained in:
Jonathan Jenne
2022-12-09 17:29:08 +01:00
parent 0a25b0925c
commit 8d6d81f488
30 changed files with 640 additions and 91 deletions

View File

@@ -1,8 +1,10 @@
Imports System.Collections.Specialized
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream
Imports ECM.JobRunner.Common
Imports Quartz
Imports Quartz.Logging.OperationName
Namespace Scheduler
Public Class JobScheduler
@@ -16,20 +18,32 @@ Namespace Scheduler
Private ReadOnly Database As MSSQLServer
Private ReadOnly Factory As Quartz.Impl.StdSchedulerFactory
Private ReadOnly State As State
Private ReadOnly Windream As Windream
Private Scheduler As IScheduler
Private Const JOB_TYPE_IMPORT As Integer = 1
Private Const JOB_TYPE_INDEX As Integer = 2
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pState As State)
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pState As State, pWindream As Windream)
LogConfig = pLogConfig
Logger = pLogConfig.GetLogger()
Factory = New Impl.StdSchedulerFactory(Settings)
Database = pDatabase
Windream = pWindream
State = pState
End Sub
Private Function BuildJobData(pJobConfig As JobConfig) As JobDataMap
Return New JobDataMap From {
{Constants.Scheduler.JOB_CONFIG_LOGCONFIG, LogConfig},
{Constants.Scheduler.JOB_CONFIG_ARGUMENTS, pJobConfig.Arguments},
{Constants.Scheduler.JOB_CONFIG_DATABASE, Database},
{Constants.Scheduler.JOB_CONFIG_STATE, State},
{Constants.Scheduler.JOB_CONFIG_WINDREAM, Windream}
}
End Function
Public Async Function Start() As Task(Of Boolean)
Try
' Log all quartz events into our standard log files
@@ -69,26 +83,39 @@ Namespace Scheduler
Return Await Scheduler.GetCurrentlyExecutingJobs()
End Function
Public Async Function ScheduleJob(pJobId As Integer) As Task
Dim oJob = State.JobDefinitions.Where(Function(j) j.Id = pJobId).SingleOrDefault()
If oJob IsNot Nothing Then
Logger.Info("Scheduling Job [{0}] manually!", oJob.Name)
Await PrepareScheduleJob(oJob)
End If
End Function
Private Async Function PrepareScheduleJob(pJob As JobDefinition) As Task
Logger.Debug("Loading Job Definition [{0}]", pJob.Name)
Logger.Debug("Job Type is [{0}]", pJob.Type.Name)
Select Case pJob.TypeId
Case JOB_TYPE_IMPORT
Dim oJobConfig = BuildJobConfig(Of Jobs.FileImportJob)(pJob)
Await ScheduleJob(Of Jobs.FileImportJob)(oJobConfig)
Case JOB_TYPE_INDEX
Dim oJobConfig = BuildJobConfig(Of Jobs.FileIndexJob)(pJob)
Await ScheduleJob(Of Jobs.FileIndexJob)(oJobConfig)
Case Else
Logger.Warn("Job for TypeId [{0}] is not implemented!", pJob.TypeId)
End Select
End Function
Private Async Sub ScheduleJobs()
Logger.Info("Loading [{0}] Job Definitions..", State.JobDefinitions.Count)
For Each oJob In State.JobDefinitions
Logger.Debug("Loading Job Definition [{0}]", oJob.Name)
Logger.Debug("Job Type is [{0}]", oJob.Type.Name)
Select Case oJob.TypeId
Case JOB_TYPE_IMPORT
Dim oJobConfig = BuildJobConfig(Of Jobs.FileImportJob)(oJob)
Await ScheduleJob(Of Jobs.FileImportJob)(oJobConfig)
Case JOB_TYPE_INDEX
Dim oJobConfig = BuildJobConfig(Of Jobs.FileIndexJob)(oJob)
Await ScheduleJob(Of Jobs.FileIndexJob)(oJobConfig)
Case Else
Logger.Warn("Job for TypeId [{0}] is not implemented!", oJob.TypeId)
End Select
Await PrepareScheduleJob(oJob)
Next
End Sub
@@ -155,15 +182,6 @@ Namespace Scheduler
End If
End Function
Private Function BuildJobData(pJobConfig As JobConfig) As JobDataMap
Return New JobDataMap From {
{Constants.Scheduler.JOB_CONFIG_LOGCONFIG, LogConfig},
{Constants.Scheduler.JOB_CONFIG_ARGUMENTS, pJobConfig.Arguments},
{Constants.Scheduler.JOB_CONFIG_DATABASE, Database},
{Constants.Scheduler.JOB_CONFIG_STATE, State}
}
End Function
Private Function BuildJob(Of T As IJob)(pJobConfig As JobConfig, pJobData As JobDataMap) As IJobDetail
Dim oJobName = GetJobName(pJobConfig)
Return JobBuilder.Create(Of T)().