Projektdateien hinzufügen.
This commit is contained in:
10
ECM.JobRunner.Windows/Scheduler/JobConfig.vb
Normal file
10
ECM.JobRunner.Windows/Scheduler/JobConfig.vb
Normal file
@@ -0,0 +1,10 @@
|
||||
Namespace Scheduler
|
||||
Public Class JobConfig
|
||||
Public Property Enabled As Boolean = False
|
||||
Public Property StartWithoutDelay As Boolean = False
|
||||
Public Property Name As String = "Unnamed Job"
|
||||
Public Property CronSchedule As String = ""
|
||||
Public Property Arguments As New Dictionary(Of String, String)
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
35
ECM.JobRunner.Windows/Scheduler/JobHistory.vb
Normal file
35
ECM.JobRunner.Windows/Scheduler/JobHistory.vb
Normal file
@@ -0,0 +1,35 @@
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports ECM.JobRunner.Common
|
||||
|
||||
Namespace Scheduler
|
||||
Public Class JobHistory
|
||||
Inherits BaseClass
|
||||
|
||||
Public ReadOnly Entries As New List(Of HistoryItem)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Sub AddSuccess(pName As String, pMessage As String)
|
||||
Entries.Add(New HistoryItem With {
|
||||
.CreatedAt = Now,
|
||||
.JobName = pName,
|
||||
.Successful = True,
|
||||
.ErrorMessage = Nothing,
|
||||
.Message = pMessage
|
||||
})
|
||||
End Sub
|
||||
|
||||
Public Sub AddError(pName As String, ErrorMessage As String)
|
||||
Entries.Add(New HistoryItem With {
|
||||
.CreatedAt = Now,
|
||||
.JobName = pName,
|
||||
.Successful = False,
|
||||
.ErrorMessage = ErrorMessage,
|
||||
.Message = ""
|
||||
})
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
40
ECM.JobRunner.Windows/Scheduler/JobListener.vb
Normal file
40
ECM.JobRunner.Windows/Scheduler/JobListener.vb
Normal file
@@ -0,0 +1,40 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Quartz
|
||||
Imports Quartz.Listener
|
||||
|
||||
Namespace Scheduler
|
||||
Public Class JobListener
|
||||
Inherits JobListenerSupport
|
||||
|
||||
Public Overrides ReadOnly Property Name As String = "JobListener"
|
||||
|
||||
Private ReadOnly Logger As Logger
|
||||
Private ReadOnly LogConfig As LogConfig
|
||||
Private ReadOnly History As JobHistory
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pJobHistory As JobHistory)
|
||||
MyBase.New()
|
||||
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogConfig.GetLogger()
|
||||
History = pJobHistory
|
||||
End Sub
|
||||
|
||||
Public Overrides Function JobWasExecuted(context As IJobExecutionContext, jobException As JobExecutionException, Optional cancellationToken As Threading.CancellationToken = Nothing) As Task
|
||||
If jobException Is Nothing Then
|
||||
If TypeOf context.Result Is JobResult Then
|
||||
Dim oResult As JobResult = context.Result
|
||||
History.AddSuccess(context.JobDetail.Key.Name, oResult.Description)
|
||||
Else
|
||||
|
||||
History.AddSuccess(context.JobDetail.Key.Name, "Job Successful!")
|
||||
End If
|
||||
Else
|
||||
History.AddError(context.JobDetail.Key.Name, jobException.Message)
|
||||
End If
|
||||
|
||||
Return MyBase.JobWasExecuted(context, jobException, cancellationToken)
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
3
ECM.JobRunner.Windows/Scheduler/JobResult.vb
Normal file
3
ECM.JobRunner.Windows/Scheduler/JobResult.vb
Normal file
@@ -0,0 +1,3 @@
|
||||
Public Class JobResult
|
||||
Public Property Description As String
|
||||
End Class
|
||||
147
ECM.JobRunner.Windows/Scheduler/JobScheduler.vb
Normal file
147
ECM.JobRunner.Windows/Scheduler/JobScheduler.vb
Normal file
@@ -0,0 +1,147 @@
|
||||
Imports System.Collections.Specialized
|
||||
Imports System.Threading
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Quartz
|
||||
Imports Quartz.Logging.OperationName
|
||||
|
||||
Namespace Scheduler
|
||||
Public Class JobScheduler
|
||||
Private ReadOnly Settings As New NameValueCollection From {
|
||||
{"quartz.serializer.type", "binary"},
|
||||
{"quartz.threadPool.threadCount", 10}
|
||||
}
|
||||
|
||||
Private ReadOnly LogConfig As LogConfig
|
||||
Private ReadOnly Logger As Logger
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly Factory As Quartz.Impl.StdSchedulerFactory
|
||||
Private ReadOnly State As State
|
||||
|
||||
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)
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogConfig.GetLogger()
|
||||
Factory = New Impl.StdSchedulerFactory(Settings)
|
||||
Database = pDatabase
|
||||
State = pState
|
||||
End Sub
|
||||
|
||||
Public Async Function Start() As Task(Of Boolean)
|
||||
Try
|
||||
' Log all quartz events into our standard log files
|
||||
Logging.LogProvider.SetCurrentLogProvider(New LogProvider(LogConfig))
|
||||
|
||||
' initialize the scheduler
|
||||
Scheduler = Await Factory.GetScheduler()
|
||||
Scheduler.ListenerManager.AddJobListener(New JobListener(LogConfig, State.JobHistory))
|
||||
|
||||
' start the scheduler
|
||||
Await Scheduler.Start()
|
||||
|
||||
' load job Config and setup job schedules
|
||||
|
||||
Logger.Info("Loading [{0}] Job Definitions..", State.JobDefinitions.Count)
|
||||
|
||||
For Each oJob In State.JobDefinitions
|
||||
Logger.Debug("Loading Job Definition [{0}]", oJob.Name)
|
||||
|
||||
Select Case oJob.TypeId
|
||||
Case JOB_TYPE_IMPORT
|
||||
Await ScheduleJob(Of Jobs.FileImportJob)(New JobConfig With {
|
||||
.Name = oJob.Name,
|
||||
.Enabled = True,
|
||||
.Arguments = New Dictionary(Of String, String) From {
|
||||
{"Name", oJob.Name}
|
||||
},
|
||||
.CronSchedule = oJob.CronSchedule
|
||||
})
|
||||
|
||||
Case JOB_TYPE_INDEX
|
||||
Await ScheduleJob(Of Jobs.FileIndexJob)(New JobConfig With {
|
||||
.Name = oJob.Name,
|
||||
.Enabled = True,
|
||||
.Arguments = New Dictionary(Of String, String) From {
|
||||
{"Name", oJob.Name}
|
||||
},
|
||||
.CronSchedule = oJob.CronSchedule
|
||||
})
|
||||
|
||||
End Select
|
||||
Next
|
||||
|
||||
' setup debug job
|
||||
|
||||
Await ScheduleJob(Of Jobs.DebugJob)(New JobConfig With {
|
||||
.Name = "Debug Job",
|
||||
.Enabled = True,
|
||||
.Arguments = New Dictionary(Of String, String) From {{"Arg1", "My awesome argument"}},
|
||||
.CronSchedule = "0 * * * * ?"
|
||||
})
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function Shutdown() As Task
|
||||
Await Scheduler.Shutdown()
|
||||
End Function
|
||||
|
||||
Public Async Function ScheduleJob(Of T As IJob)(pJobConfig As JobConfig) As Task
|
||||
Dim oJobName As String = pJobConfig.Name
|
||||
Dim oTriggerName As String = $"{oJobName}-TRIGGER"
|
||||
|
||||
pJobConfig.Name = oJobName
|
||||
|
||||
Dim oJobData As New JobDataMap From {
|
||||
{Constants.Scheduler.JOB_CONFIG_LOGCONFIG, LogConfig},
|
||||
{Constants.Scheduler.JOB_CONFIG_ARGUMENTS, pJobConfig.Arguments},
|
||||
{Constants.Scheduler.JOB_CONFIG_DATABASE, Database}
|
||||
}
|
||||
|
||||
Dim oJob = JobBuilder.Create(Of T)().
|
||||
WithIdentity(oJobName).
|
||||
UsingJobData(oJobData).
|
||||
Build()
|
||||
|
||||
Dim oTrigger = TriggerBuilder.Create().
|
||||
WithIdentity(oTriggerName).
|
||||
StartNow().
|
||||
WithCronSchedule(pJobConfig.CronSchedule).
|
||||
Build()
|
||||
|
||||
If pJobConfig.Enabled Then
|
||||
Await Scheduler.ScheduleJob(oJob, oTrigger)
|
||||
|
||||
Logger.Info("Job {0} scheduled.", oJobName)
|
||||
Else
|
||||
Logger.Info("Job {0} is disabled.", oJobName)
|
||||
End If
|
||||
|
||||
If pJobConfig.StartWithoutDelay Then
|
||||
Dim oDebugJob = JobBuilder.Create(Of T)().
|
||||
WithIdentity(oJobName & "-DEBUG").
|
||||
UsingJobData(oJobData).
|
||||
Build()
|
||||
|
||||
Dim oDebugTrigger = TriggerBuilder.Create().
|
||||
WithIdentity(oTriggerName & "-DEBUG").
|
||||
StartAt(DateBuilder.FutureDate(10, IntervalUnit.Second)).
|
||||
Build()
|
||||
|
||||
Logger.Info("Job {0} will start in 10 Seconds.", oJobName)
|
||||
Await Scheduler.ScheduleJob(oDebugJob, oDebugTrigger)
|
||||
End If
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
21
ECM.JobRunner.Windows/Scheduler/Jobs/BaseJob.vb
Normal file
21
ECM.JobRunner.Windows/Scheduler/Jobs/BaseJob.vb
Normal file
@@ -0,0 +1,21 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Quartz
|
||||
|
||||
Namespace Scheduler.Jobs
|
||||
Public Class BaseJob
|
||||
Friend LogConfig As LogConfig
|
||||
Friend Logger As Logger
|
||||
Friend Database As MSSQLServer
|
||||
|
||||
Public Function InitializeJob(context As IJobExecutionContext) As Dictionary(Of String, String)
|
||||
Dim oJobData = context.MergedJobDataMap
|
||||
LogConfig = oJobData.Item(Constants.Scheduler.JOB_CONFIG_LOGCONFIG)
|
||||
Database = oJobData.Item(Constants.Scheduler.JOB_CONFIG_DATABASE)
|
||||
Logger = LogConfig.GetLogger()
|
||||
|
||||
Return oJobData.Item(Constants.Scheduler.JOB_CONFIG_ARGUMENTS)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
25
ECM.JobRunner.Windows/Scheduler/Jobs/DebugJob.vb
Normal file
25
ECM.JobRunner.Windows/Scheduler/Jobs/DebugJob.vb
Normal file
@@ -0,0 +1,25 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Quartz
|
||||
|
||||
Namespace Scheduler.Jobs
|
||||
Public Class DebugJob
|
||||
Inherits BaseJob
|
||||
Implements IJob
|
||||
|
||||
Private Function IJob_Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
|
||||
Dim oArgs = MyBase.InitializeJob(context)
|
||||
Dim oArg1 = oArgs.Item("Arg1")
|
||||
|
||||
Logger.Info("I'm a debug Job!")
|
||||
Logger.Info("Arg1: [{0}]", oArg1)
|
||||
|
||||
Dim oResult = New JobResult() With {
|
||||
.Description = $"I'm a debug job and my result was [{Guid.NewGuid}]."
|
||||
}
|
||||
|
||||
context.Result = oResult
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
26
ECM.JobRunner.Windows/Scheduler/Jobs/FileImportJob.vb
Normal file
26
ECM.JobRunner.Windows/Scheduler/Jobs/FileImportJob.vb
Normal file
@@ -0,0 +1,26 @@
|
||||
Imports ECM.JobRunner.Windows.Scheduler.Jobs
|
||||
Imports Quartz
|
||||
|
||||
|
||||
Namespace Scheduler.Jobs
|
||||
Public Class FileImportJob
|
||||
Inherits BaseJob
|
||||
Implements IJob
|
||||
|
||||
Public Function Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
|
||||
Dim oArgs = MyBase.InitializeJob(context)
|
||||
Dim oName = oArgs.Item("Name")
|
||||
|
||||
Logger.Info("Running File Import [{0}]", oName)
|
||||
|
||||
Dim oResult = New JobResult() With {
|
||||
.Description = $"File Import Job [{oName}] completed!"
|
||||
}
|
||||
|
||||
context.Result = oResult
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
24
ECM.JobRunner.Windows/Scheduler/Jobs/FileIndexJob.vb
Normal file
24
ECM.JobRunner.Windows/Scheduler/Jobs/FileIndexJob.vb
Normal file
@@ -0,0 +1,24 @@
|
||||
Imports ECM.JobRunner.Windows.Scheduler.Jobs
|
||||
Imports Quartz
|
||||
|
||||
Namespace Scheduler.Jobs
|
||||
Public Class FileIndexJob
|
||||
Inherits BaseJob
|
||||
Implements IJob
|
||||
|
||||
Public Function Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
|
||||
Dim oArgs = MyBase.InitializeJob(context)
|
||||
Dim oName = oArgs.Item("Name")
|
||||
|
||||
Logger.Info("Running File Index [{0}]", oName)
|
||||
|
||||
Dim oResult = New JobResult() With {
|
||||
.Description = $"File Index Job [{oName}] completed!"
|
||||
}
|
||||
|
||||
context.Result = oResult
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user