JobRunner: Update to use tables
This commit is contained in:
@@ -1,44 +1,29 @@
|
||||
Imports System.Collections.Specialized
|
||||
Imports DigitalData.Modules.Config
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Jobs
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Services.JobRunner.Config
|
||||
Imports Quartz
|
||||
Imports Quartz.Impl
|
||||
Imports Quartz.Logging
|
||||
|
||||
Public Class JobRunner
|
||||
Private _LogConfig As LogConfig
|
||||
Private _Logger As DigitalData.Modules.Logging.Logger
|
||||
Private _firebird As Firebird
|
||||
Private _mssql As MSSQLServer
|
||||
Private ReadOnly _LogConfig As LogConfig
|
||||
Private ReadOnly _Logger As DigitalData.Modules.Logging.Logger
|
||||
Private ReadOnly _firebird As Firebird
|
||||
Private ReadOnly _mssql As MSSQLServer
|
||||
Private ReadOnly _config As Config
|
||||
|
||||
Private _Props As New NameValueCollection From {
|
||||
{"quartz.serializer.type", "binary"},
|
||||
{"quartz.threadPool.threadCount", 10}
|
||||
}
|
||||
Private _factory As StdSchedulerFactory
|
||||
Private _scheduler As IScheduler
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer, Firebird As Firebird)
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
_firebird = Firebird
|
||||
_mssql = MSSQL
|
||||
Try
|
||||
Dim directory As New IO.DirectoryInfo(_LogConfig.LogDirectory)
|
||||
|
||||
For Each file As IO.FileInfo In directory.GetFiles
|
||||
If (Now - file.CreationTime).Days > 29 Then
|
||||
file.Delete()
|
||||
Else
|
||||
Exit For
|
||||
End If
|
||||
|
||||
|
||||
Next
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
Public Sub New(pLogConfig As LogConfig, pConfig As Config, pMSSQL As MSSQLServer, pFirebird As Firebird)
|
||||
_LogConfig = pLogConfig
|
||||
_Logger = pLogConfig.GetLogger()
|
||||
_firebird = pFirebird
|
||||
_mssql = pMSSQL
|
||||
_config = pConfig
|
||||
End Sub
|
||||
|
||||
Public Async Sub Start()
|
||||
@@ -48,7 +33,8 @@ Public Class JobRunner
|
||||
_Logger.Info("Starting JobRunner")
|
||||
|
||||
Dim oProps As New NameValueCollection From {
|
||||
{"quartz.serializer.type", "binary"}
|
||||
{"quartz.serializer.type", "binary"},
|
||||
{"quartz.threadPool.threadCount", 10}
|
||||
}
|
||||
_factory = New StdSchedulerFactory(oProps)
|
||||
_scheduler = Await _factory.GetScheduler()
|
||||
@@ -57,26 +43,30 @@ Public Class JobRunner
|
||||
Await _scheduler.Start()
|
||||
|
||||
' [START] Job Scheduling
|
||||
Await ScheduleJob(Of ADJob)("ADSync", My.Settings.ADSYNC_CONFIG)
|
||||
Await ScheduleJob(Of TestJob)("TestJob", My.Settings.TEST_CONFIG)
|
||||
Await ScheduleJob(Of GraphQLJob)("GraphQLJob", My.Settings.GRAPHQL_CONFIG)
|
||||
Await ScheduleJob(Of ADJob)("ADSync", GetJobConfig(JobConfig.JobType.ADSync))
|
||||
Await ScheduleJob(Of TestJob)("TestJob", GetJobConfig(JobConfig.JobType.Test))
|
||||
Await ScheduleJob(Of GraphQLJob)("GraphQLJob", GetJobConfig(JobConfig.JobType.GraphQL))
|
||||
' [END] Job Scheduling
|
||||
|
||||
Catch ex As Exception
|
||||
_Logger.Warn("Job Failed.")
|
||||
_Logger.Warn("Job Failed with message: [{0}].", ex.Message)
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Async Function ScheduleJob(Of T As Quartz.IJob)(JobName As String, JobConfigString As String) As Task
|
||||
Public Function GetJobConfig(pName As JobConfig.JobType) As JobConfig
|
||||
Return _config.Jobs.Where(Function(j) j.Name = pName).SingleOrDefault()
|
||||
End Function
|
||||
|
||||
Public Async Function ScheduleJob(Of T As Quartz.IJob)(JobName As String, pJobConfig As JobConfig) As Task
|
||||
Dim oJobIdentity As String = JobName
|
||||
Dim oTriggerIdentity As String = JobName & "-Trigger"
|
||||
Dim oJobConfig As JobConfig = JobConfigParser.ParseConfig(JobConfigString)
|
||||
Dim oJobConfig As JobConfig = JobConfigParser.ParseConfig(pJobConfig)
|
||||
Dim oJobData As New JobDataMap From {
|
||||
{"LogConfig", _LogConfig},
|
||||
{"Firebird", _firebird},
|
||||
{"MSSQL", _mssql},
|
||||
{"Args", oJobConfig.Arguments}
|
||||
{"Args", oJobConfig.Args}
|
||||
}
|
||||
|
||||
Dim oJob = JobBuilder.Create(Of T)().
|
||||
@@ -87,7 +77,7 @@ Public Class JobRunner
|
||||
Dim oTrigger = TriggerBuilder.Create().
|
||||
WithIdentity(oTriggerIdentity).
|
||||
StartNow().
|
||||
WithCronSchedule(oJobConfig.CronExpression).
|
||||
WithCronSchedule(oJobConfig.CronSchedule).
|
||||
Build()
|
||||
|
||||
If oJobConfig.Enabled Then
|
||||
@@ -98,8 +88,8 @@ Public Class JobRunner
|
||||
_Logger.Info("Job {0} is disabled.", JobName)
|
||||
End If
|
||||
|
||||
' If StartImmediately is True, start Job after 10 Seconds
|
||||
If oJobConfig.StartImmediately Then
|
||||
' If StartWithoutDelay is True, start Job after 10 Seconds
|
||||
If oJobConfig.StartWithoutDelay Then
|
||||
Dim oDebugJob = JobBuilder.Create(Of T)().
|
||||
WithIdentity(oJobIdentity & "-DEBUG").
|
||||
UsingJobData(oJobData).
|
||||
@@ -130,8 +120,6 @@ Public Class JobRunner
|
||||
_Logger = Logger
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Private Function GetLogger(name As String) As Logging.Logger Implements ILogProvider.GetLogger
|
||||
Return Function(level, func, exception, parameters)
|
||||
If exception IsNot Nothing Then
|
||||
|
||||
Reference in New Issue
Block a user