23-12-2022

This commit is contained in:
Jonathan Jenne
2022-12-23 13:27:30 +01:00
parent e3f271ac33
commit 7e7eee7299
10 changed files with 130 additions and 36 deletions

View File

@@ -1,4 +1,5 @@
Imports System.Collections.Specialized
Imports System.Runtime.InteropServices
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream
@@ -88,11 +89,20 @@ Namespace Scheduler
If oJob IsNot Nothing Then
Logger.Info("Scheduling Job [{0}] manually!", oJob.Name)
Await PrepareScheduleJob(oJob)
Await PrepareScheduleJob(oJob, pStartManually:=True)
End If
End Function
Private Async Function PrepareScheduleJob(pJob As JobDefinition) As Task
Private Async Sub ScheduleJobs()
Logger.Info("Loading [{0}] Job Definitions..", State.JobDefinitions.Count)
For Each oJob In State.JobDefinitions
Await PrepareScheduleJob(oJob, pStartManually:=False)
Next
End Sub
Private Async Function PrepareScheduleJob(pJob As JobDefinition, pStartManually As Boolean) As Task
Logger.Debug("Loading Job Definition [{0}]", pJob.Name)
Logger.Debug("Job Type is [{0}]", pJob.Type.Name)
@@ -110,15 +120,6 @@ Namespace Scheduler
End Select
End Function
Private Async Sub ScheduleJobs()
Logger.Info("Loading [{0}] Job Definitions..", State.JobDefinitions.Count)
For Each oJob In State.JobDefinitions
Await PrepareScheduleJob(oJob)
Next
End Sub
Private Function BuildJobConfig(Of TJob As IJob)(pJob As JobDefinition) As JobConfig
Return New JobConfig With {
.Name = pJob.Name,
@@ -131,8 +132,11 @@ Namespace Scheduler
}
End Function
Private Async Function ScheduleJob(Of T As IJob)(pJobConfig As JobConfig) As Task
If Await Scheduler.CheckExists(New JobKey(GetJobName(pJobConfig))) Then
Private Async Function ScheduleJob(Of T As IJob)(pJobConfig As JobConfig, pStartManually As Boolean) As Task
If pStartManually = True Then
Logger.Debug("Manual run, scheduling..")
Await DoScheduleJobWithoutDelay(Of T)(pJobConfig)
ElseIf Await Scheduler.CheckExists(New JobKey(GetJobName(pJobConfig))) Then
Logger.Debug("Job already exists, rescheduling..")
Await DoRescheduleJob(Of T)(pJobConfig)
Else
@@ -156,12 +160,12 @@ Namespace Scheduler
End Function
Private Async Function DoScheduleJob(Of T As IJob)(pJobConfig As JobConfig) As Task
Dim oJobName As String = GetJobName(pJobConfig)
Dim oTriggerName As String = GetTriggerName(pJobConfig)
Dim oTrigger As ITrigger = BuildTrigger(pJobConfig)
Dim oJobName As String = GetJobName(pJobConfig)
Dim oJobData As JobDataMap = BuildJobData(pJobConfig)
Dim oJob As IJobDetail = BuildJob(Of T)(pJobConfig, oJobData)
Dim oTrigger As ITrigger = BuildTrigger(pJobConfig)
If pJobConfig.Enabled Then
Await Scheduler.ScheduleJob(oJob, oTrigger)
@@ -172,14 +176,23 @@ Namespace Scheduler
End If
If pJobConfig.StartWithoutDelay Then
Dim oNoDelayTrigger = TriggerBuilder.Create().
Await DoScheduleJobWithoutDelay(Of T)(pJobConfig)
End If
End Function
Private Async Function DoScheduleJobWithoutDelay(Of T As IJob)(pJobConfig As JobConfig) As Task
Dim oJobName As String = GetJobName(pJobConfig)
Dim oJobData As JobDataMap = BuildJobData(pJobConfig)
Dim oJob As IJobDetail = BuildJob(Of T)(pJobConfig, oJobData)
Dim oTriggerName As String = GetTriggerName(pJobConfig)
Dim oNoDelayTrigger = TriggerBuilder.Create().
WithIdentity(oTriggerName & "-NO-DELAY").
StartAt(DateBuilder.FutureDate(10, IntervalUnit.Second)).
Build()
Logger.Info("Job {0} will start in 10 Seconds.", oJobName)
Await Scheduler.ScheduleJob(oJob, oNoDelayTrigger)
End If
Logger.Info("Job {0} will start in 10 Seconds.", oJobName)
Await Scheduler.ScheduleJob(oJob, oNoDelayTrigger)
End Function
Private Function BuildJob(Of T As IJob)(pJobConfig As JobConfig, pJobData As JobDataMap) As IJobDetail