2022-12-20 12:00:15 +01:00

93 lines
3.4 KiB
VB.net

Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream
Imports ECM.JobRunner.Common
Imports Quartz
Namespace Scheduler.Jobs
Public Class BaseJob
Friend LogConfig As LogConfig
Friend Logger As Logger
Friend Database As MSSQLServer
Friend Windream As Windream
Friend State As State
Friend Id As Integer
Friend ExecutionId As String
Friend Name As String
Friend JobSteps As New List(Of StatusItem.HistoryStep)
Private ctx As IJobExecutionContext
Public Function InitializeJob(context As IJobExecutionContext) As Dictionary(Of String, String)
ctx = context
Dim oJobData = context.MergedJobDataMap
Dim oArgs As Dictionary(Of String, String) = oJobData.Item(Constants.Scheduler.JOB_CONFIG_ARGUMENTS)
LogConfig = oJobData.Item(Constants.Scheduler.JOB_CONFIG_LOGCONFIG)
Database = oJobData.Item(Constants.Scheduler.JOB_CONFIG_DATABASE)
State = oJobData.Item(Constants.Scheduler.JOB_CONFIG_STATE)
Windream = oJobData.Item(Constants.Scheduler.JOB_CONFIG_WINDREAM)
Logger = LogConfig.GetLogger()
ExecutionId = Guid.NewGuid.ToString()
Id = Integer.Parse(oArgs.Item("Id"))
Name = oArgs.Item("Name")
State.JobStatus.Start(ctx)
Logger.Info("Job [{0}] is starting!", Id)
Return oJobData.Item(Constants.Scheduler.JOB_CONFIG_ARGUMENTS)
End Function
Public Sub UpdateProgress(pCurrentValue As Integer, pTotalValue As Integer)
State.JobStatus.Update(ctx, pCurrentValue, pTotalValue)
End Sub
Public Sub LogDebug(pMessage As String, ParamArray pArgs As String())
Logger.Debug(pMessage, pArgs)
JobSteps.Add(New StatusItem.HistoryStep With {
.Message = String.Format(pMessage, pArgs),
.Level = StatusItem.STEP_DEBUG
})
End Sub
Public Sub LogInfo(pMessage As String, ParamArray pArgs As String())
Logger.Info(pMessage, pArgs)
JobSteps.Add(New StatusItem.HistoryStep With {
.Message = String.Format(pMessage, pArgs),
.Level = StatusItem.STEP_INFO
})
End Sub
Public Sub LogWarning(pMessage As String, ParamArray pArgs As String())
Logger.Warn(pMessage, pArgs)
JobSteps.Add(New StatusItem.HistoryStep With {
.Message = String.Format(pMessage, pArgs),
.Level = StatusItem.STEP_WARNING
})
End Sub
Public Sub LogError(pMessage As String, ParamArray pArgs As String())
Logger.Error(pMessage, pArgs)
JobSteps.Add(New StatusItem.HistoryStep With {
.Message = String.Format(pMessage, pArgs),
.Level = StatusItem.STEP_ERROR
})
End Sub
Public Function CompleteJob(pMessage As String) As Task(Of Boolean)
ctx.Result = State.JobStatus.CompleteWithSuccess(ctx, JobSteps, pMessage)
Return Task.FromResult(True)
End Function
Public Function CompleteJobWithError(pException As Exception) As Task(Of Boolean)
ctx.Result = State.JobStatus.CompleteWithError(ctx, JobSteps, pException)
Return Task.FromResult(False)
End Function
End Class
End Namespace