20-12-2022
This commit is contained in:
@@ -47,16 +47,26 @@ Public Class JobStatus
|
||||
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
|
||||
oStatus.Waiting = False
|
||||
End If
|
||||
|
||||
Return oStatus
|
||||
Return DoComplete(pJob, pSteps)
|
||||
End Function
|
||||
|
||||
Public Function CompleteWithWaiting(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 Waiting", oStatus.Id)
|
||||
|
||||
If oStatus IsNot Nothing Then
|
||||
oStatus.SuccessMessage = pMessage
|
||||
oStatus.Successful = True
|
||||
oStatus.Waiting = True
|
||||
End If
|
||||
|
||||
Return DoComplete(pJob, pSteps)
|
||||
End Function
|
||||
|
||||
Public Function CompleteWithSuccess(pJob As Quartz.IJobExecutionContext, pSteps As List(Of StatusItem.HistoryStep), pMessage As String) As StatusItem
|
||||
@@ -65,23 +75,35 @@ Public Class JobStatus
|
||||
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
|
||||
oStatus.Successful = True
|
||||
oStatus.Waiting = False
|
||||
End If
|
||||
|
||||
Return DoComplete(pJob, pSteps)
|
||||
End Function
|
||||
|
||||
Private Function DoComplete(pJob As Quartz.IJobExecutionContext, pSteps As List(Of StatusItem.HistoryStep))
|
||||
Dim oStatus = GetJobStatus(pJob)
|
||||
|
||||
oStatus.ProgressCurrent = oStatus.ProgressTotal
|
||||
oStatus.ExecutionTime = pJob.JobRunTime
|
||||
oStatus.Executing = False
|
||||
oStatus.CompleteTime = Date.Now
|
||||
oStatus.Steps = pSteps
|
||||
|
||||
Return oStatus
|
||||
End Function
|
||||
|
||||
Private Function GetJobStatus(pJob As Quartz.IJobExecutionContext) As StatusItem
|
||||
Dim oJobId = GetJobId(pJob)
|
||||
Dim oJobId As String = GetJobId(pJob)
|
||||
Logger.Debug("Getting status for job id [{0}]", oJobId)
|
||||
|
||||
Dim oExists = Entries.Where(Function(e) e.JobId = oJobId).Any()
|
||||
Logger.Debug("Job exists: [{0}]", oExists)
|
||||
|
||||
If Not oExists Then
|
||||
Logger.Debug("Creating status for job id [{0}]", oJobId)
|
||||
Entries.Add(New StatusItem With {
|
||||
.JobId = oJobId,
|
||||
.Id = Guid.NewGuid.ToString(),
|
||||
@@ -89,7 +111,7 @@ Public Class JobStatus
|
||||
})
|
||||
End If
|
||||
|
||||
Return Entries.Where(Function(e) e.Id = oJobId).SingleOrDefault()
|
||||
Return Entries.Where(Function(e) e.JobId = oJobId).Single()
|
||||
End Function
|
||||
|
||||
Private Function GetJobId(pJob As Quartz.IJobExecutionContext) As String
|
||||
|
||||
@@ -29,11 +29,12 @@ Namespace Scheduler.Jobs
|
||||
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")
|
||||
Logger = LogConfig.GetLogger(Name)
|
||||
|
||||
State.JobStatus.Start(ctx)
|
||||
|
||||
Logger.Info("Job [{0}] is starting!", Id)
|
||||
@@ -83,6 +84,11 @@ Namespace Scheduler.Jobs
|
||||
Return Task.FromResult(True)
|
||||
End Function
|
||||
|
||||
Public Function CompleteJobWithWaiting(pMessage As String) As Task(Of Boolean)
|
||||
ctx.Result = State.JobStatus.CompleteWithWaiting(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)
|
||||
|
||||
@@ -29,7 +29,7 @@ Namespace Scheduler.Jobs
|
||||
|
||||
If IO.Directory.Exists(oProfile.SourceFolder) = False Then
|
||||
LogError("Source directory [{0}] does not exist!", oProfile.SourceFolder)
|
||||
Return Task.FromResult(False)
|
||||
Return CompleteJobWithError(New IO.DirectoryNotFoundException($"Source directory [{oProfile.SourceFolder}] does not exist!"))
|
||||
End If
|
||||
|
||||
Dim oRecursive As Boolean = oProfile.IncludeSubfolders
|
||||
@@ -40,24 +40,24 @@ Namespace Scheduler.Jobs
|
||||
|
||||
If oFileNames.Count = 0 Then
|
||||
Logger.Info("No Files for Profile [{0}]", Name)
|
||||
Return CompleteJob("No files for profile")
|
||||
Return CompleteJobWithWaiting("No files for profile")
|
||||
End If
|
||||
|
||||
LogInfo("{0} files found in source directory {1}", oFileNames.Count, oProfile.SourceFolder)
|
||||
LogInfo("{0} files found in source directory {1}", oFileNames.Count.ToString, oProfile.SourceFolder)
|
||||
|
||||
' - [ ] Process Rules, build list of files and indexes
|
||||
' - [x] Process Regex to filter out files
|
||||
' - [x] Check time to filter out files
|
||||
' - [ ] (Check if files can be accessed)
|
||||
' - [ ] Check if backup is needed and backup files
|
||||
' - [ ] Import into windream
|
||||
' - [x] Import into windream
|
||||
' - [ ] Create original subfolder structure
|
||||
' - [ ] Create DateTime Subfolders
|
||||
' - [x] Check if file exists and version
|
||||
' - [x] Do import
|
||||
' - [ ] Check for filesize 0
|
||||
' - [ ] Write indexes (using data from getimportfile)
|
||||
' - [ ] Check if orig file should be deleted
|
||||
' - [x] Write indexes (using data from getimportfile)
|
||||
' - [x] Check if orig file should be deleted
|
||||
' - [ ] (delete subdirectories in source path)
|
||||
|
||||
Dim oFiles = oFileNames.
|
||||
@@ -71,12 +71,22 @@ Namespace Scheduler.Jobs
|
||||
LogDebug("{0} Files filtered out for being too new.", oDateFilteredCount)
|
||||
oFilteredFiles = oDateFilteredFiles
|
||||
|
||||
If oFilteredFiles.Count = 0 Then
|
||||
Logger.Info("No Files for Profile [{0}]", Name)
|
||||
Return CompleteJobWithWaiting("No files for profile")
|
||||
End If
|
||||
|
||||
' Process Regex to filter out files
|
||||
Dim oRegexFilteredFiles = oFilteredFiles.Where(Function(f) Not FileMatchesRegex(f, oRegexList))
|
||||
Dim oRegexFilteredCount = oFilteredFiles.Except(oRegexFilteredFiles).Count()
|
||||
LogDebug("{0} Files filtered out for matching exclusion Regex.", oRegexFilteredCount)
|
||||
oFilteredFiles = oDateFilteredFiles
|
||||
|
||||
If oFilteredFiles.Count = 0 Then
|
||||
Logger.Info("No Files for Profile [{0}]", Name)
|
||||
Return CompleteJobWithWaiting("No files for profile")
|
||||
End If
|
||||
|
||||
'-------------------------------------------------------------------------------------------------
|
||||
' After this point, files are treated as processed and are being deleted before finishing the job
|
||||
'-------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user