JobRunner, ADInterface
This commit is contained in:
130
Service.JobRunner/JobRunner.vb
Normal file
130
Service.JobRunner/JobRunner.vb
Normal file
@@ -0,0 +1,130 @@
|
||||
Imports System.Collections.Specialized
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Jobs
|
||||
Imports DigitalData.Modules.Logging
|
||||
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 _Props As New NameValueCollection From {
|
||||
{"quartz.serializer.type", "binary"}
|
||||
}
|
||||
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
|
||||
End Sub
|
||||
|
||||
Public Async Sub Start()
|
||||
Try
|
||||
Logging.LogProvider.SetCurrentLogProvider(New LogProvider(_Logger))
|
||||
|
||||
_Logger.Info("Starting JobRunner")
|
||||
|
||||
Dim oProps As New NameValueCollection From {
|
||||
{"quartz.serializer.type", "binary"}
|
||||
}
|
||||
_factory = New StdSchedulerFactory(oProps)
|
||||
_scheduler = Await _factory.GetScheduler()
|
||||
|
||||
_Logger.Info("Starting Scheduler..")
|
||||
Await _scheduler.Start()
|
||||
_Logger.Info("Done")
|
||||
|
||||
Dim oJobData As New JobDataMap From {
|
||||
{"LogConfig", _LogConfig},
|
||||
{"Firebird", _firebird},
|
||||
{"MSSQL", _mssql},
|
||||
{"RootPath", My.Settings.JOB_ADSYNC_ROOT_PATH}
|
||||
}
|
||||
|
||||
Dim oJobDetail = JobBuilder.Create(Of ADJob)().
|
||||
WithIdentity("activedirectory-sync").
|
||||
UsingJobData(oJobData).
|
||||
Build()
|
||||
|
||||
Dim oTrigger = TriggerBuilder.Create().
|
||||
WithIdentity("activedirectory-sync-trigger").
|
||||
StartNow().
|
||||
WithCronSchedule("0 0/1 * * * ?").
|
||||
Build()
|
||||
|
||||
_Logger.Info("Starting ADSync Job..")
|
||||
Await _scheduler.ScheduleJob(oJobDetail, oTrigger)
|
||||
_Logger.Info("Done")
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Async Sub [Stop]()
|
||||
_Logger.Info("Stopping JobRunner")
|
||||
Await _scheduler.Shutdown()
|
||||
End Sub
|
||||
|
||||
Public Class ADJob
|
||||
Implements Quartz.IJob
|
||||
|
||||
Public Function Execute(context As IJobExecutionContext) As Task Implements Quartz.IJob.Execute
|
||||
Dim oJobData = context.MergedJobDataMap
|
||||
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
|
||||
Dim oFirebird As Firebird = oJobData.Item("Firebird")
|
||||
Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
|
||||
Dim oRootPath As String = oJobData.Item("RootPath")
|
||||
Dim oADJobArgs = New ADSyncArgs() With {
|
||||
.RootPath = oRootPath
|
||||
}
|
||||
|
||||
Dim oADSyncJob As New ADSyncJob(oLogConfig, oFirebird, oMSSQL)
|
||||
oADSyncJob.Start(oADJobArgs)
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Private Class LogProvider
|
||||
Implements ILogProvider
|
||||
|
||||
Private _Logger As DigitalData.Modules.Logging.Logger
|
||||
|
||||
Public Sub New(Logger As DigitalData.Modules.Logging.Logger)
|
||||
MyBase.New()
|
||||
_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
|
||||
_Logger.Error(exception)
|
||||
ElseIf level >= LogLevel.Debug AndAlso func IsNot Nothing Then
|
||||
_Logger.Debug(func(), parameters)
|
||||
ElseIf level >= LogLevel.Info AndAlso func IsNot Nothing Then
|
||||
_Logger.Info(func(), parameters)
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
End Function
|
||||
|
||||
Private Function OpenNestedContext(message As String) As IDisposable Implements ILogProvider.OpenNestedContext
|
||||
_Logger.Warn("OpenNestedContext is not implemented")
|
||||
Throw New NotImplementedException()
|
||||
End Function
|
||||
|
||||
Private Function OpenMappedContext(key As String, value As String) As IDisposable Implements ILogProvider.OpenMappedContext
|
||||
_Logger.Warn("OpenMappedContext is not implemented")
|
||||
Throw New NotImplementedException()
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user