Jonathan Jenne 45f8dd2aad 16-12-2022
2022-12-16 15:59:26 +01:00

87 lines
3.0 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 ResultItems As New List(Of HistoryItem.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)
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 LogStep(pLevel As HistoryItem.StepLevel, pMessage As String, ParamArray pArgs As String())
ResultItems.Add(New HistoryItem.HistoryStep With {
.Message = String.Format(pMessage, pArgs),
.Level = pLevel
})
End Sub
Public Function CompleteJob() As Task(Of Boolean)
ctx.Result = New JobResult With {
.Successful = True,
.Steps = ResultItems,
.Description = "Job completed."
}
State.JobStatus.Complete(ctx)
Return Task.FromResult(True)
End Function
Public Function CompleteJob(pCompletionMessage As String) As Task(Of Boolean)
ctx.Result = New JobResult With {
.Successful = True,
.Steps = ResultItems,
.Description = pCompletionMessage
}
State.JobStatus.Complete(ctx)
Return Task.FromResult(True)
End Function
Public Function CompleteJob(pException As Exception) As Task(Of Boolean)
ctx.Result = New JobResult With {
.Successful = False,
.Steps = ResultItems,
.Description = pException.Message
}
State.JobStatus.Complete(ctx)
Return Task.FromResult(False)
End Function
End Class
End Namespace