Jobs: New Version of GraphQLJob

This commit is contained in:
Jonathan Jenne 2021-03-11 13:01:16 +01:00
parent 2ef98e4a06
commit a183ae975d

View File

@ -16,6 +16,8 @@ Public Class GraphQLJob
Inherits JobBase Inherits JobBase
Implements IJob(Of GraphQLArgs) Implements IJob(Of GraphQLArgs)
Private Const PLACEHOLDER_STATIC = "STATIC:"
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer) Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer)
MyBase.New(LogConfig, Nothing, MSSQL) MyBase.New(LogConfig, Nothing, MSSQL)
End Sub End Sub
@ -64,21 +66,23 @@ Public Class GraphQLJob
For Each oQuery As GraphQL.Query In oQueryList For Each oQuery As GraphQL.Query In oQueryList
Try Try
_Logger.NewBlock($"Query [{oQuery.Name}]")
Dim oConnectionId As Integer = oQuery.ConnectionId Dim oConnectionId As Integer = oQuery.ConnectionId
Dim oConnectionString = _MSSQL.Get_ConnectionStringforID(oConnectionId) Dim oConnectionString = _MSSQL.Get_ConnectionStringforID(oConnectionId)
Dim oDatabase As New MSSQLServer(_LogConfig, oConnectionString) Dim oDatabase As New MSSQLServer(_LogConfig, oConnectionString)
_Logger.Info("Resetting data for query [{0}] with constraint [{1}]", oQuery.Name, oQuery.QueryConstraint)
' Reset all records to status = 0 ' Reset all records to status = 0
_Logger.Info("Resetting data with constraint [{1}]", oQuery.Name, oQuery.QueryConstraint)
Dim oResetSQL = $"UPDATE {oQuery.DestinationTable} SET STATUS = 0" Dim oResetSQL = $"UPDATE {oQuery.DestinationTable} SET STATUS = 0"
If oQuery.QueryConstraint <> String.Empty Then If oQuery.QueryConstraint <> String.Empty Then
oResetSQL &= $" WHERE {oQuery.QueryConstraint}" oResetSQL &= $" WHERE {oQuery.QueryConstraint}"
End If End If
_MSSQL.ExecuteNonQuery(oResetSQL) _MSSQL.ExecuteNonQuery(oResetSQL)
_Logger.Info("Getting data for query [{0}]", oQuery.Name) _Logger.Info("Getting data..", oQuery.Name)
' get the data from GraphQL ' get the data from GraphQL
Dim oDataResponse = oInterface.GetData(oQuery.QueryString, oQuery.OperationName) Dim oDataResponse = oInterface.GetData(oQuery.QueryString, oQuery.OperationName)
@ -111,21 +115,21 @@ Public Class GraphQLJob
Continue For Continue For
End If End If
' Finally delete all old records, when: ' Finally delete all old records
' - ClearBeforeFill is true, which should be the last query for a given Operation Dim oDeleteSQL = $"DELETE FROM {oQuery.DestinationTable} WHERE STATUS = 0"
' - QueryConstraint is not empty, which means the records produced by this query can be selected easily If oQuery.QueryConstraint <> String.Empty Then
If oQuery.ClearBeforeFill = True Or oQuery.QueryConstraint <> String.Empty Then oDeleteSQL &= $" AND {oQuery.QueryConstraint}"
Dim oDeleteSQL = $"DELETE FROM {oQuery.DestinationTable} WHERE STATUS = 0"
If oQuery.QueryConstraint <> String.Empty Then
oDeleteSQL &= $" AND {oQuery.QueryConstraint}"
End If
_MSSQL.ExecuteNonQuery(oDeleteSQL)
End If End If
_Logger.Info("Success, deleting old records..", oQuery.Name)
_MSSQL.ExecuteNonQuery(oDeleteSQL)
Catch ex As Exception Catch ex As Exception
_Logger.Warn("Error while getting Data for Name/OperationName [{0}]/[{1}]", oQuery.Name, oQuery.OperationName) _Logger.Warn("Error while getting Data for Name/OperationName [{0}]/[{1}]", oQuery.Name, oQuery.OperationName)
_Logger.Error(ex) _Logger.Error(ex)
_Logger.Info("Failure, deleting new records..", oQuery.Name)
' If a crash happens, delete all records which were inserted in this run, ' If a crash happens, delete all records which were inserted in this run,
' thus going back to the previous state ' thus going back to the previous state
Dim oDeleteSQL = $"DELETE FROM {oQuery.DestinationTable} WHERE STATUS = 1" Dim oDeleteSQL = $"DELETE FROM {oQuery.DestinationTable} WHERE STATUS = 1"
@ -133,6 +137,8 @@ Public Class GraphQLJob
oDeleteSQL &= $" AND {oQuery.QueryConstraint}" oDeleteSQL &= $" AND {oQuery.QueryConstraint}"
End If End If
_MSSQL.ExecuteNonQuery(oDeleteSQL) _MSSQL.ExecuteNonQuery(oDeleteSQL)
Finally
_Logger.EndBlock()
End Try End Try
Next Next
@ -172,13 +178,22 @@ Public Class GraphQLJob
Dim oKeys As New List(Of String) Dim oKeys As New List(Of String)
For Each oMapping In QueryData.MappingFields For Each oMapping In QueryData.MappingFields
Dim oToken = oResultItem.SelectToken(oMapping.SourcePath) Dim oValue As String = String.Empty
If oToken Is Nothing Then If oMapping.SourcePath.StartsWith(PLACEHOLDER_STATIC) Then
_Logger.Warn("HandleResponse: Could not find value at SourcePath: {0}", oMapping.SourcePath) oValue = oMapping.SourcePath.Replace(PLACEHOLDER_STATIC, String.Empty)
Else
Dim oToken = oResultItem.SelectToken(oMapping.SourcePath)
If oToken Is Nothing Then
_Logger.Warn("HandleResponse: Could not find value at SourcePath: {0}", oMapping.SourcePath)
oValue = String.Empty
Else
oValue = oToken.ToString
End If
End If End If
oValues.Add(oToken.ToString()) oValues.Add(oValue)
oKeys.Add(oMapping.DestinationColumn) oKeys.Add(oMapping.DestinationColumn)
Next Next