99 lines
3.4 KiB
VB.net
99 lines
3.4 KiB
VB.net
Imports DigitalData.Modules.Base
|
|
Imports DigitalData.Modules.Logging
|
|
Imports ECM.JobRunner.Common
|
|
|
|
Public Class JobStatus
|
|
Inherits BaseClass
|
|
|
|
Public ReadOnly Entries As New List(Of StatusItem)
|
|
|
|
Public Sub New(pLogConfig As LogConfig)
|
|
MyBase.New(pLogConfig)
|
|
End Sub
|
|
|
|
Public Sub Start(pJob As Quartz.IJobExecutionContext)
|
|
Dim oStatus = GetJobStatus(pJob)
|
|
|
|
Logger.Info("Starting Job [{0}]", oStatus.Id)
|
|
|
|
If oStatus IsNot Nothing Then
|
|
oStatus.Name = pJob.JobDetail.Key.Name
|
|
oStatus.StartTime = Date.Now
|
|
oStatus.UpdateTime = Date.Now
|
|
oStatus.Executing = True
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub Update(pJob As Quartz.IJobExecutionContext, pCurrent As Integer, pTotal As Integer)
|
|
Dim oStatus = GetJobStatus(pJob)
|
|
|
|
Logger.Debug("Updating Job [{0}] with Status [{1}/{2}]", oStatus.Id, pCurrent, pTotal)
|
|
|
|
If oStatus IsNot Nothing Then
|
|
oStatus.ProgressTotal = pTotal
|
|
oStatus.ProgressCurrent = pCurrent
|
|
oStatus.ExecutionTime = pJob.JobRunTime
|
|
oStatus.UpdateTime = Date.Now
|
|
End If
|
|
End Sub
|
|
|
|
Public Function CompleteWithError(pJob As Quartz.IJobExecutionContext, pSteps As List(Of StatusItem.HistoryStep), pException As Exception) As StatusItem
|
|
Return CompleteWithError(pJob, pSteps, pException.Message)
|
|
End Function
|
|
|
|
Public Function CompleteWithError(pJob As Quartz.IJobExecutionContext, pSteps As List(Of StatusItem.HistoryStep), pMessage As String) As StatusItem
|
|
Dim oStatus = GetJobStatus(pJob)
|
|
|
|
Logger.Info("Completing Job [{0}] with Error", oStatus.Id)
|
|
|
|
If oStatus IsNot Nothing Then
|
|
oStatus.ProgressCurrent = oStatus.ProgressTotal
|
|
oStatus.ExecutionTime = pJob.JobRunTime
|
|
oStatus.Executing = False
|
|
oStatus.CompleteTime = Date.Now
|
|
oStatus.FailureMessage = pMessage
|
|
oStatus.Successful = False
|
|
oStatus.Steps = pSteps
|
|
End If
|
|
|
|
Return oStatus
|
|
End Function
|
|
|
|
Public Function CompleteWithSuccess(pJob As Quartz.IJobExecutionContext, pSteps As List(Of StatusItem.HistoryStep), pMessage As String) As StatusItem
|
|
Dim oStatus = GetJobStatus(pJob)
|
|
|
|
Logger.Info("Completing Job [{0}] with Success", oStatus.Id)
|
|
|
|
If oStatus IsNot Nothing Then
|
|
oStatus.ProgressCurrent = oStatus.ProgressTotal
|
|
oStatus.ExecutionTime = pJob.JobRunTime
|
|
oStatus.Executing = False
|
|
oStatus.CompleteTime = Date.Now
|
|
oStatus.SuccessMessage = pMessage
|
|
oStatus.Successful = False
|
|
oStatus.Steps = pSteps
|
|
End If
|
|
|
|
Return oStatus
|
|
End Function
|
|
|
|
Private Function GetJobStatus(pJob As Quartz.IJobExecutionContext) As StatusItem
|
|
Dim oJobId = GetJobId(pJob)
|
|
Dim oExists = Entries.Where(Function(e) e.JobId = oJobId).Any()
|
|
|
|
If Not oExists Then
|
|
Entries.Add(New StatusItem With {
|
|
.JobId = oJobId,
|
|
.Id = Guid.NewGuid.ToString(),
|
|
.Steps = New List(Of StatusItem.HistoryStep)
|
|
})
|
|
End If
|
|
|
|
Return Entries.Where(Function(e) e.Id = oJobId).SingleOrDefault()
|
|
End Function
|
|
|
|
Private Function GetJobId(pJob As Quartz.IJobExecutionContext) As String
|
|
Return pJob.JobDetail.Key.ToString() & pJob.FireTimeUtc.ToString("u")
|
|
End Function
|
|
End Class
|