2 Commits

Author SHA1 Message Date
Jonathan Jenne
ce6d30d882 ZUGFeRDService: Version 2.1.1 2022-07-01 13:06:52 +02:00
Jonathan Jenne
41f9e552d5 Improve UpdateRejected to run every hour, only update files from last 12 hours 2022-07-01 13:06:06 +02:00
2 changed files with 43 additions and 19 deletions

View File

@@ -12,8 +12,8 @@ Imports System.Runtime.InteropServices
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("Digital Data")>
<Assembly: AssemblyProduct("DDZUGFeRDService")>
<Assembly: AssemblyCopyright("Copyright © 2021")>
<Assembly: AssemblyTrademark("1.11.0.0")>
<Assembly: AssemblyCopyright("Copyright © 2022")>
<Assembly: AssemblyTrademark("2.1.1.0")>
<Assembly: ComVisible(False)>
@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' übernehmen, indem Sie "*" eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("2.1.0.0")>
<Assembly: AssemblyFileVersion("2.1.0.0")>
<Assembly: AssemblyVersion("2.1.1.0")>
<Assembly: AssemblyFileVersion("2.1.1.0")>

View File

@@ -21,6 +21,9 @@ Public Class ThreadRunner
Private ReadOnly _jobArguments As WorkerArgs
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)
_logConfig = LogConfig
_logger = _logConfig.GetLogger()
@@ -137,26 +140,47 @@ Public Class ThreadRunner
End If
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
Try
Try
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
MaybeUpdateRejected()
Dim args As WorkerArgs = e.Argument
Dim oArgs As WorkerArgs = e.Argument
_logger.Debug("Background worker running..")
Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird, _config.Config.MSSQLEmailOutAccountID, _config.Config.PORTAL_NAME, _mssql)
job.Start(args)
Dim oJob As New ImportZUGFeRDFiles(_logConfig, _firebird, _config.Config.MSSQLEmailOutAccountID, _config.Config.PORTAL_NAME, _mssql)
oJob.Start(oArgs)
Catch ex As Exception
_logger.Warn("Background worker failed!")
_logger.Error(ex)