JobRunner: Update to use tables

This commit is contained in:
Jonathan Jenne 2022-11-24 14:37:25 +01:00
parent 138b0ac127
commit d8f3323723
4 changed files with 70 additions and 49 deletions

View File

@ -0,0 +1,25 @@
Imports DigitalData.Modules.Jobs
Public Class Config
Public Property Debug As Boolean = False
Public Property SQLConnectionString As String = ""
Public Property Firebird As New FirebirdConfig
Public Property Jobs As New List(Of JobConfig)
'Public Enum JobType
' ADSync
' GraphQL
' Test
'End Enum
Public Class FirebirdConfig
Public Property DataSource As String = "172.24.12.41"
Public Property Database As String = "172.24.12.41:E:\DB\Firebird\Databases\EDMI_TEMPLATE\EDMI_MASTER.FDB"
Public Property User As String = "sysdba"
Public Property Password As String = "dd"
End Class
End Class

View File

@ -1,44 +1,29 @@
Imports System.Collections.Specialized Imports System.Collections.Specialized
Imports DigitalData.Modules.Config
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Jobs Imports DigitalData.Modules.Jobs
Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Logging
Imports DigitalData.Services.JobRunner.Config
Imports Quartz Imports Quartz
Imports Quartz.Impl Imports Quartz.Impl
Imports Quartz.Logging Imports Quartz.Logging
Public Class JobRunner Public Class JobRunner
Private _LogConfig As LogConfig Private ReadOnly _LogConfig As LogConfig
Private _Logger As DigitalData.Modules.Logging.Logger Private ReadOnly _Logger As DigitalData.Modules.Logging.Logger
Private _firebird As Firebird Private ReadOnly _firebird As Firebird
Private _mssql As MSSQLServer 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 _factory As StdSchedulerFactory
Private _scheduler As IScheduler Private _scheduler As IScheduler
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer, Firebird As Firebird) Public Sub New(pLogConfig As LogConfig, pConfig As Config, pMSSQL As MSSQLServer, pFirebird As Firebird)
_LogConfig = LogConfig _LogConfig = pLogConfig
_Logger = LogConfig.GetLogger() _Logger = pLogConfig.GetLogger()
_firebird = Firebird _firebird = pFirebird
_mssql = MSSQL _mssql = pMSSQL
Try _config = pConfig
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
End Sub End Sub
Public Async Sub Start() Public Async Sub Start()
@ -48,7 +33,8 @@ Public Class JobRunner
_Logger.Info("Starting JobRunner") _Logger.Info("Starting JobRunner")
Dim oProps As New NameValueCollection From { Dim oProps As New NameValueCollection From {
{"quartz.serializer.type", "binary"} {"quartz.serializer.type", "binary"},
{"quartz.threadPool.threadCount", 10}
} }
_factory = New StdSchedulerFactory(oProps) _factory = New StdSchedulerFactory(oProps)
_scheduler = Await _factory.GetScheduler() _scheduler = Await _factory.GetScheduler()
@ -57,26 +43,30 @@ Public Class JobRunner
Await _scheduler.Start() Await _scheduler.Start()
' [START] Job Scheduling ' [START] Job Scheduling
Await ScheduleJob(Of ADJob)("ADSync", My.Settings.ADSYNC_CONFIG) Await ScheduleJob(Of ADJob)("ADSync", GetJobConfig(JobConfig.JobType.ADSync))
Await ScheduleJob(Of TestJob)("TestJob", My.Settings.TEST_CONFIG) Await ScheduleJob(Of TestJob)("TestJob", GetJobConfig(JobConfig.JobType.Test))
Await ScheduleJob(Of GraphQLJob)("GraphQLJob", My.Settings.GRAPHQL_CONFIG) Await ScheduleJob(Of GraphQLJob)("GraphQLJob", GetJobConfig(JobConfig.JobType.GraphQL))
' [END] Job Scheduling ' [END] Job Scheduling
Catch ex As Exception Catch ex As Exception
_Logger.Warn("Job Failed.") _Logger.Warn("Job Failed with message: [{0}].", ex.Message)
_Logger.Error(ex) _Logger.Error(ex)
End Try End Try
End Sub 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 oJobIdentity As String = JobName
Dim oTriggerIdentity As String = JobName & "-Trigger" 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 { Dim oJobData As New JobDataMap From {
{"LogConfig", _LogConfig}, {"LogConfig", _LogConfig},
{"Firebird", _firebird}, {"Firebird", _firebird},
{"MSSQL", _mssql}, {"MSSQL", _mssql},
{"Args", oJobConfig.Arguments} {"Args", oJobConfig.Args}
} }
Dim oJob = JobBuilder.Create(Of T)(). Dim oJob = JobBuilder.Create(Of T)().
@ -87,7 +77,7 @@ Public Class JobRunner
Dim oTrigger = TriggerBuilder.Create(). Dim oTrigger = TriggerBuilder.Create().
WithIdentity(oTriggerIdentity). WithIdentity(oTriggerIdentity).
StartNow(). StartNow().
WithCronSchedule(oJobConfig.CronExpression). WithCronSchedule(oJobConfig.CronSchedule).
Build() Build()
If oJobConfig.Enabled Then If oJobConfig.Enabled Then
@ -98,8 +88,8 @@ Public Class JobRunner
_Logger.Info("Job {0} is disabled.", JobName) _Logger.Info("Job {0} is disabled.", JobName)
End If End If
' If StartImmediately is True, start Job after 10 Seconds ' If StartWithoutDelay is True, start Job after 10 Seconds
If oJobConfig.StartImmediately Then If oJobConfig.StartWithoutDelay Then
Dim oDebugJob = JobBuilder.Create(Of T)(). Dim oDebugJob = JobBuilder.Create(Of T)().
WithIdentity(oJobIdentity & "-DEBUG"). WithIdentity(oJobIdentity & "-DEBUG").
UsingJobData(oJobData). UsingJobData(oJobData).
@ -130,8 +120,6 @@ Public Class JobRunner
_Logger = Logger _Logger = Logger
End Sub End Sub
Private Function GetLogger(name As String) As Logging.Logger Implements ILogProvider.GetLogger Private Function GetLogger(name As String) As Logging.Logger Implements ILogProvider.GetLogger
Return Function(level, func, exception, parameters) Return Function(level, func, exception, parameters)
If exception IsNot Nothing Then If exception IsNot Nothing Then

View File

@ -50,6 +50,10 @@
<ApplicationManifest>My Project\app.manifest</ApplicationManifest> <ApplicationManifest>My Project\app.manifest</ApplicationManifest>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="DigitalData.Modules.Config, Version=1.1.4.1, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\DDModules\Config\bin\Debug\DigitalData.Modules.Config.dll</HintPath>
</Reference>
<Reference Include="DigitalData.Modules.Database, Version=2.2.7.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="DigitalData.Modules.Database, Version=2.2.7.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\DDModules\Database\bin\Debug\DigitalData.Modules.Database.dll</HintPath> <HintPath>..\..\DDModules\Database\bin\Debug\DigitalData.Modules.Database.dll</HintPath>
@ -101,6 +105,7 @@
<Import Include="System.Threading.Tasks" /> <Import Include="System.Threading.Tasks" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Config.vb" />
<Compile Include="JobRunner.vb" /> <Compile Include="JobRunner.vb" />
<Compile Include="Jobs\GraphQLJob.vb" /> <Compile Include="Jobs\GraphQLJob.vb" />
<Compile Include="Jobs\ADJob.vb" /> <Compile Include="Jobs\ADJob.vb" />

View File

@ -1,31 +1,34 @@
Imports DigitalData.Modules.Logging Imports System.IO
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Logging.LogConfig Imports DigitalData.Modules.Logging.LogConfig
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Imports DigitalData.Services.JobRunner Imports DigitalData.Modules.Config
Public Class JobRunnerService Public Class JobRunnerService
Private _logConfig As LogConfig Private _logConfig As LogConfig
Private _logger As Logger Private _logger As Logger
Private _config As ConfigManager(Of Config)
Private _mssql As MSSQLServer Private _mssql As MSSQLServer
Private _firebird As Firebird Private _firebird As Firebird
Private _jobrunner As JobRunner Private _jobrunner As JobRunner
Protected Overrides Sub OnStart(ByVal args() As String) Protected Overrides Sub OnStart(ByVal args() As String)
_logConfig = New LogConfig(PathType.CustomPath, My.Settings.LOG_PATH) With { _logConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"))
.Debug = My.Settings.LOG_DEBUG
}
_logger = _logConfig.GetLogger() _logger = _logConfig.GetLogger()
_logger.Info("Starting Service {0}", ServiceName) _logger.Info("Starting Service {0}", ServiceName)
_config = New ConfigManager(Of Config)(_logConfig, My.Application.Info.DirectoryPath)
Dim oFirebird = _config.Config.Firebird
Try Try
_mssql = New MSSQLServer(_logConfig, My.Settings.SQL_CONNECTIONSTRING) _mssql = New MSSQLServer(_logConfig, _config.Config.SQLConnectionString)
_firebird = New Firebird(_logConfig, My.Settings.FIREBIRD_SERVER, My.Settings.FIREBIRD_DATABASE, My.Settings.FIREBIRD_USER, My.Settings.FIREBIRD_PASSWORD) _firebird = New Firebird(_logConfig, oFirebird.DataSource, oFirebird.Database, oFirebird.User, oFirebird.Password)
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)
End Try End Try
Try Try
_jobrunner = New JobRunner(_logConfig, _mssql, _firebird) _jobrunner = New JobRunner(_logConfig, _config.Config, _mssql, _firebird)
_jobrunner.Start() _jobrunner.Start()
Catch ex As Exception Catch ex As Exception
_logger.Error(ex) _logger.Error(ex)