add quartz scheduler to jobrunner
This commit is contained in:
parent
0374016cde
commit
f68e5cf19f
@ -40,6 +40,9 @@
|
||||
<setting name="JOB_ADSYNC_ROOT_PATH" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
<setting name="DB_CONNECTIONSTRING" serializeAs="String">
|
||||
<value />
|
||||
</setting>
|
||||
</DigitalData.Services.JobRunner.My.MySettings>
|
||||
</applicationSettings>
|
||||
</configuration>
|
||||
@ -11,12 +11,14 @@ Public Class JobRunner
|
||||
Private ReadOnly _interval As Long
|
||||
Private ReadOnly _logConfig As LogConfig
|
||||
Private ReadOnly _logger As Logger
|
||||
Private ReadOnly _mssql As MSSQLServer
|
||||
Private ReadOnly _firebird As Firebird
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Firebird As Firebird, Interval As Long)
|
||||
Public Sub New(LogConfig As LogConfig, Firebird As Firebird, MSSQL As MSSQLServer, Interval As Long)
|
||||
_logConfig = LogConfig
|
||||
_logger = _logConfig.GetLogger()
|
||||
_firebird = Firebird
|
||||
_mssql = MSSQL
|
||||
_interval = Interval
|
||||
|
||||
_workerTimer = New Timer()
|
||||
@ -58,7 +60,7 @@ Public Class JobRunner
|
||||
_logger.Debug("Background worker running..")
|
||||
|
||||
Dim args As WorkerArgs = e.Argument
|
||||
Dim oJob As New ADSyncJob(_logConfig, _firebird)
|
||||
Dim oJob As New ADSyncJob(_logConfig, _firebird, _mssql)
|
||||
Dim oArgs As New ADSyncArgs() With {
|
||||
.Enabled = My.Settings.JOB_ADSYNC_ENABLED,
|
||||
.Interval = My.Settings.JOB_ADSYNC_INTERVAL,
|
||||
|
||||
@ -51,6 +51,9 @@
|
||||
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.4.5.11\lib\net45\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Quartz, Version=3.0.7.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Quartz.3.0.7\lib\net452\Quartz.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
@ -58,6 +61,7 @@
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.Runtime.Remoting" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.ServiceProcess" />
|
||||
@ -82,6 +86,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="JobRunner.vb" />
|
||||
<Compile Include="JobRunner2.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
|
||||
113
JobRunner/JobRunner2.vb
Normal file
113
JobRunner/JobRunner2.vb
Normal file
@ -0,0 +1,113 @@
|
||||
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 JobRunner2
|
||||
Private _LogConfig As LogConfig
|
||||
Private _Logger As 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()
|
||||
Logging.LogProvider.SetCurrentLogProvider(New LogProvider(_Logger))
|
||||
|
||||
Dim oProps As New NameValueCollection From {
|
||||
{"quartz.serializer.type", "binary"}
|
||||
}
|
||||
_factory = New StdSchedulerFactory(oProps)
|
||||
_scheduler = Await _factory.GetScheduler()
|
||||
|
||||
Await _scheduler.Start()
|
||||
|
||||
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("1 0 * * *").
|
||||
Build()
|
||||
|
||||
Await _scheduler.ScheduleJob(oJobDetail, oTrigger)
|
||||
End Sub
|
||||
|
||||
Public Async Sub [Stop]()
|
||||
Await _scheduler.Shutdown()
|
||||
End Sub
|
||||
|
||||
Public Class ADJob
|
||||
Implements Quartz.IJob
|
||||
|
||||
Public Async 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)
|
||||
|
||||
Await Task.CompletedTask
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Private Class LogProvider
|
||||
Implements ILogProvider
|
||||
|
||||
Private _Logger As Modules.Logging.Logger
|
||||
|
||||
Public Sub New(Logger As 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 level >= LogLevel.Info AndAlso func IsNot Nothing Then
|
||||
_Logger.Info(func())
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
End Function
|
||||
|
||||
Private Function OpenNestedContext(message As String) As IDisposable Implements ILogProvider.OpenNestedContext
|
||||
Throw New NotImplementedException()
|
||||
End Function
|
||||
|
||||
Private Function OpenMappedContext(key As String, value As String) As IDisposable Implements ILogProvider.OpenMappedContext
|
||||
Throw New NotImplementedException()
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Class
|
||||
9
JobRunner/My Project/Settings.Designer.vb
generated
9
JobRunner/My Project/Settings.Designer.vb
generated
@ -143,6 +143,15 @@ Namespace My
|
||||
Return CType(Me("JOB_ADSYNC_ROOT_PATH"),String)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
<Global.System.Configuration.ApplicationScopedSettingAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Configuration.DefaultSettingValueAttribute("")> _
|
||||
Public ReadOnly Property DB_CONNECTIONSTRING() As String
|
||||
Get
|
||||
Return CType(Me("DB_CONNECTIONSTRING"),String)
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
|
||||
@ -32,5 +32,8 @@
|
||||
<Setting Name="JOB_ADSYNC_ROOT_PATH" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
<Setting Name="DB_CONNECTIONSTRING" Type="System.String" Scope="Application">
|
||||
<Value Profile="(Default)" />
|
||||
</Setting>
|
||||
</Settings>
|
||||
</SettingsFile>
|
||||
@ -7,8 +7,9 @@ Public Class WindowsService
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
Private _firebird As Firebird
|
||||
Private _mssql As MSSQLServer
|
||||
|
||||
Private _jobRunner As JobRunner
|
||||
Private _jobRunner As JobRunner2
|
||||
|
||||
Protected Overrides Sub OnStart(ByVal args() As String)
|
||||
_logConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"))
|
||||
@ -23,13 +24,21 @@ Public Class WindowsService
|
||||
Dim oInterval As Long = My.Settings.JOB_INTERVAL
|
||||
|
||||
_firebird = New Firebird(_logConfig, oDataSource, oDatabase, oUser, oPassword)
|
||||
_mssql = New MSSQLServer(_logConfig, My.Settings.DB_CONNECTIONSTRING)
|
||||
|
||||
Try
|
||||
_jobRunner = New JobRunner(_logConfig, _firebird, oInterval)
|
||||
_jobRunner = New JobRunner2(_logConfig, _mssql, _firebird)
|
||||
_jobRunner.Start()
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
|
||||
'Try
|
||||
' _jobRunner = New JobRunner(_logConfig, _firebird, oInterval)
|
||||
' _jobRunner.Start()
|
||||
'Catch ex As Exception
|
||||
' _logger.Error(ex)
|
||||
'End Try
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnStop()
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NLog" version="4.5.11" targetFramework="net461" />
|
||||
<package id="Quartz" version="3.0.7" targetFramework="net461" />
|
||||
</packages>
|
||||
Loading…
x
Reference in New Issue
Block a user