EDMIService: Add Quartz Scheduler, Add Caching for Datatables
This commit is contained in:
40
Service.EDMIService/Scheduler/DatatableJob.vb
Normal file
40
Service.EDMIService/Scheduler/DatatableJob.vb
Normal file
@@ -0,0 +1,40 @@
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Quartz
|
||||
|
||||
Public Class DatatableJob
|
||||
Implements IJob
|
||||
|
||||
Public Function Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
|
||||
Dim oJobData = context.MergedJobDataMap
|
||||
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
|
||||
Dim oCronJobTitle As String = oJobData.Item("CronJobTitle")
|
||||
Dim oDetailRow As DataRow = oJobData.Item("CronJobDetails")
|
||||
Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
|
||||
|
||||
Dim oConnectionId As Integer = oDetailRow.Item("CON_ID")
|
||||
Dim oTitle As String = oDetailRow.Item("TITLE")
|
||||
Dim oDatatableName As String = oDetailRow.Item("DT_NAME")
|
||||
Dim oSQL As String = oDetailRow.Item("COMMAND")
|
||||
|
||||
Dim oLogger As Logger = oLogConfig.GetLogger()
|
||||
oLogger.Debug("Running Command-Job [{0}]", oTitle)
|
||||
oLogger.Debug("Datatable Name: {0}", oDatatableName)
|
||||
oLogger.Debug("Connection Id: {0}", oConnectionId)
|
||||
|
||||
Dim oConnectionString = oMSSQL.Get_ConnectionStringforID(oConnectionId)
|
||||
|
||||
Try
|
||||
Dim oResult = oMSSQL.GetDatatableWithConnection(oSQL, oConnectionString)
|
||||
oResult.TableName = oDatatableName
|
||||
oLogger.Debug("Result Datatable contains [{0}] rows", oResult.Rows.Count)
|
||||
|
||||
' Das Ergebnis speichern
|
||||
context.Result = oResult
|
||||
Catch ex As Exception
|
||||
oLogger.Warn("Unhandled exception while executing SQL for Datatable {}")
|
||||
End Try
|
||||
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
End Class
|
||||
49
Service.EDMIService/Scheduler/JobListener.vb
Normal file
49
Service.EDMIService/Scheduler/JobListener.vb
Normal file
@@ -0,0 +1,49 @@
|
||||
Imports System.Threading
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports Quartz
|
||||
Imports Quartz.Listener
|
||||
|
||||
Public Class JobListener
|
||||
Inherits JobListenerSupport
|
||||
Public Overrides ReadOnly Property Name As String = "JobListener"
|
||||
Public Property Dataset As DataSet
|
||||
|
||||
Private ReadOnly _Logger As Logger
|
||||
Private ReadOnly _LogConfig As LogConfig
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, ResultDataSet As DataSet)
|
||||
MyBase.New()
|
||||
|
||||
_LogConfig = LogConfig
|
||||
_Logger = LogConfig.GetLogger()
|
||||
Dataset = ResultDataSet
|
||||
End Sub
|
||||
|
||||
Public Overrides Function JobWasExecuted(context As IJobExecutionContext, jobException As JobExecutionException, Optional cancellationToken As CancellationToken = Nothing) As Task
|
||||
Try
|
||||
Dim oDataTable As DataTable = context.Result
|
||||
Dim oDetailRow As DataRow = context.MergedJobDataMap.Item("CronJobDetails")
|
||||
Dim oDatatableName As String = oDetailRow.Item("DT_NAME")
|
||||
Dim oDatatableNameTemp As String = oDatatableName & "-TEMP"
|
||||
|
||||
If Dataset.Tables.Contains(oDatatableName) Then
|
||||
_Logger.Debug("DataTable exists, renaming and replacing")
|
||||
' Rename the new table, add TEMP suffix
|
||||
oDataTable.TableName = oDatatableNameTemp
|
||||
' Add the new table to the dataset
|
||||
Dataset.Tables.Add(oDataTable)
|
||||
' Remove the old table
|
||||
Dataset.Tables.Remove(oDatatableName)
|
||||
' Rename the new table
|
||||
Dataset.Tables.Item(oDatatableNameTemp).TableName = oDatatableName
|
||||
Else
|
||||
_Logger.Debug("DataTable does not exist, adding")
|
||||
Dataset.Tables.Add(oDataTable)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
End Try
|
||||
|
||||
Return MyBase.JobWasExecuted(context, jobException, cancellationToken)
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user