06-12-2022
This commit is contained in:
65
ECM.JobRunner.Windows/Scheduler/JobStatus.vb
Normal file
65
ECM.JobRunner.Windows/Scheduler/JobStatus.vb
Normal file
@@ -0,0 +1,65 @@
|
||||
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.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
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub Complete(pJob As Quartz.IJobExecutionContext)
|
||||
Dim oStatus = GetJobStatus(pJob)
|
||||
|
||||
Logger.Info("Completing Job [{0}]", oStatus.Id)
|
||||
|
||||
If oStatus IsNot Nothing Then
|
||||
oStatus.ProgressCurrent = oStatus.ProgressTotal
|
||||
oStatus.ExecutionTime = pJob.JobRunTime
|
||||
oStatus.Executing = False
|
||||
oStatus.CompleteTime = Date.Now
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Function GetJobStatus(pJob As Quartz.IJobExecutionContext) As StatusItem
|
||||
Dim oJobId = GetJobId(pJob)
|
||||
Dim oExists = Entries.Where(Function(e) e.Id = oJobId).Any()
|
||||
|
||||
If Not oExists Then
|
||||
Entries.Add(New StatusItem With {.Id = oJobId})
|
||||
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
|
||||
Reference in New Issue
Block a user