Improve UpdateRejected to run every hour, only update files from last 12 hours
This commit is contained in:
@@ -21,6 +21,9 @@ Public Class ThreadRunner
|
|||||||
Private ReadOnly _jobArguments As WorkerArgs
|
Private ReadOnly _jobArguments As WorkerArgs
|
||||||
Private ReadOnly _mssql As MSSQLServer
|
Private ReadOnly _mssql As MSSQLServer
|
||||||
|
|
||||||
|
Private ReadOnly RejectedMaxDifferenceInMinutes As Integer = 60
|
||||||
|
Private RejectedLastRun As Date = Now.AddMinutes(-(RejectedMaxDifferenceInMinutes - 1))
|
||||||
|
|
||||||
Public Sub New(LogConfig As LogConfig, ConfigManager As ConfigManager(Of Config), Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing)
|
Public Sub New(LogConfig As LogConfig, ConfigManager As ConfigManager(Of Config), Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing)
|
||||||
_logConfig = LogConfig
|
_logConfig = LogConfig
|
||||||
_logger = _logConfig.GetLogger()
|
_logger = _logConfig.GetLogger()
|
||||||
@@ -137,26 +140,47 @@ Public Class ThreadRunner
|
|||||||
End If
|
End If
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Sub MaybeUpdateRejected()
|
||||||
|
Try
|
||||||
|
Dim oTimeUnit = "HOUR"
|
||||||
|
Dim oTimeValue = 12
|
||||||
|
|
||||||
|
Dim oDifference As TimeSpan = Now - RejectedLastRun
|
||||||
|
If oDifference.TotalMinutes < RejectedMaxDifferenceInMinutes Then
|
||||||
|
Exit Sub
|
||||||
|
End If
|
||||||
|
|
||||||
|
_logger.Info("Updating rejected files in Firebird.")
|
||||||
|
|
||||||
|
Dim oSQL = $"
|
||||||
|
SELECT [EMAIL_MSGID]
|
||||||
|
FROM TBEMLP_HISTORY
|
||||||
|
WHERE (STATUS = 'REJECTED' OR CUST_REJECTED = 1)
|
||||||
|
AND DATEDIFF({oTimeUnit}, CHANGED_WHEN, GETDATE()) <= {oTimeValue}
|
||||||
|
ORDER BY GUID DESC"
|
||||||
|
Dim oDT As DataTable = _mssql.GetDatatable(oSQL)
|
||||||
|
If Not IsNothing(oDT) Then
|
||||||
|
For Each oROW As DataRow In oDT.Rows
|
||||||
|
Dim oUpdate = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET REJECTED = True WHERE MESSAGE_ID = '{oROW.Item(0)}' and REJECTED = false"
|
||||||
|
_firebird.ExecuteNonQuery(oUpdate)
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
Catch ex As Exception
|
||||||
|
_logger.Warn("Error while Updating REJECTED State: " & ex.Message)
|
||||||
|
Finally
|
||||||
|
RejectedLastRun = Now
|
||||||
|
End Try
|
||||||
|
End Sub
|
||||||
|
|
||||||
Private Sub DoWork(sender As Object, e As DoWorkEventArgs) Handles _workerThread.DoWork
|
Private Sub DoWork(sender As Object, e As DoWorkEventArgs) Handles _workerThread.DoWork
|
||||||
Try
|
Try
|
||||||
Try
|
MaybeUpdateRejected()
|
||||||
Dim oSQL = "SELECT [EMAIL_MSGID] FROM TBEMLP_HISTORY WHERE (STATUS = 'REJECTED' OR CUST_REJECTED = 1) and DATEDIFF(DAY,CHANGED_WHEN,GETDATE()) <= 2 order by guid desc"
|
|
||||||
Dim oDT As DataTable = _mssql.GetDatatable(oSQL)
|
|
||||||
If Not IsNothing(oDT) Then
|
|
||||||
For Each oROW As DataRow In oDT.Rows
|
|
||||||
Dim oUpdate = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET REJECTED = True WHERE MESSAGE_ID = '{oROW.Item(0)}' and REJECTED = false"
|
|
||||||
_firebird.ExecuteNonQuery(oUpdate)
|
|
||||||
Next
|
|
||||||
End If
|
|
||||||
Catch ex As Exception
|
|
||||||
_logger.Warn("Error while Updating REJECTED State: " & ex.Message)
|
|
||||||
End Try
|
|
||||||
|
|
||||||
Dim args As WorkerArgs = e.Argument
|
Dim oArgs As WorkerArgs = e.Argument
|
||||||
_logger.Debug("Background worker running..")
|
_logger.Debug("Background worker running..")
|
||||||
|
|
||||||
Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird, _config.Config.MSSQLEmailOutAccountID, _config.Config.PORTAL_NAME, _mssql)
|
Dim oJob As New ImportZUGFeRDFiles(_logConfig, _firebird, _config.Config.MSSQLEmailOutAccountID, _config.Config.PORTAL_NAME, _mssql)
|
||||||
job.Start(args)
|
oJob.Start(oArgs)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Warn("Background worker failed!")
|
_logger.Warn("Background worker failed!")
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user