finish adsync for now, add test job

This commit is contained in:
Jonathan Jenne
2019-04-23 14:36:08 +02:00
parent a8ed35aee2
commit b5559955a3
11 changed files with 235 additions and 42 deletions

View File

@@ -1,4 +1,5 @@
Imports System.Collections.Specialized
Imports System.Text.RegularExpressions
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Jobs
Imports DigitalData.Modules.Logging
@@ -39,34 +40,50 @@ Public Class JobRunner
_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}
}
' [START] Job Scheduling
' ADSync
Await ScheduleJob(Of ADJob)("ADSync", My.Settings.ADSYNC_CONFIG)
' Test Job
Await ScheduleJob(Of TestJob)("TestJob", My.Settings.TEST_CONFIG)
' [END] Job Scheduling
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.Warn("Job Failed.")
_Logger.Error(ex)
End Try
End Sub
Public Async Function ScheduleJob(Of T As Quartz.IJob)(JobName As String, JobConfigString As String) As Task
Dim oJobIdentity As String = JobName
Dim oTriggerIdentity As String = JobName & "-Trigger"
Dim oJobConfig As JobConfig = JobConfigParser.ParseConfig(JobConfigString)
Dim oJobData As New JobDataMap From {
{"LogConfig", _LogConfig},
{"Firebird", _firebird},
{"MSSQL", _mssql},
{"Args", oJobConfig.Arguments}
}
Dim oJobDetail = JobBuilder.Create(Of T)().
WithIdentity(oJobIdentity).
UsingJobData(oJobData).
Build()
Dim oTrigger = TriggerBuilder.Create().
WithIdentity(oTriggerIdentity).
StartNow().
WithCronSchedule(oJobConfig.CronExpression).
Build()
If oJobConfig.Enabled Then
Await _scheduler.ScheduleJob(oJobDetail, oTrigger)
_Logger.Info("Job {0} started.", JobName)
Else
_Logger.Info("Job {0} is disabled.", JobName)
End If
End Function
Public Async Sub [Stop]()
_Logger.Info("Stopping JobRunner")
Await _scheduler.Shutdown()
@@ -80,7 +97,9 @@ Public Class JobRunner
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 oArgs As Dictionary(Of String, String) = oJobData.Item("Args")
Dim oRootPath As String = oArgs.Item("RootPath")
Dim oADJobArgs = New ADSyncArgs() With {
.RootPath = oRootPath
}
@@ -91,6 +110,21 @@ Public Class JobRunner
Return Task.FromResult(True)
End Function
End Class
Public Class TestJob
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 oArgs As Dictionary(Of String, String) = oJobData.Item("Args")
Dim oArg1 As String = oArgs.Item("Arg1")
Dim oLogger = oLogConfig.GetLogger()
oLogger.Info("Running Test Job With Arg1: {0}", oArg1)
Return Task.FromResult(True)
End Function
End Class
Private Class LogProvider
Implements ILogProvider
@@ -126,5 +160,4 @@ Public Class JobRunner
Throw New NotImplementedException()
End Function
End Class
End Class