From a183ae975dd4966baa28ad271331adf26e3f444c Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 11 Mar 2021 13:01:16 +0100 Subject: [PATCH] Jobs: New Version of GraphQLJob --- Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb | 49 ++++++++++++++++--------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb b/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb index 741464df..01ebedde 100644 --- a/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb +++ b/Modules.Jobs/EDMI/GraphQL/GraphQLJob.vb @@ -16,6 +16,8 @@ Public Class GraphQLJob Inherits JobBase Implements IJob(Of GraphQLArgs) + Private Const PLACEHOLDER_STATIC = "STATIC:" + Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer) MyBase.New(LogConfig, Nothing, MSSQL) End Sub @@ -64,21 +66,23 @@ Public Class GraphQLJob For Each oQuery As GraphQL.Query In oQueryList Try + _Logger.NewBlock($"Query [{oQuery.Name}]") + Dim oConnectionId As Integer = oQuery.ConnectionId Dim oConnectionString = _MSSQL.Get_ConnectionStringforID(oConnectionId) 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 + _Logger.Info("Resetting data with constraint [{1}]", oQuery.Name, oQuery.QueryConstraint) + Dim oResetSQL = $"UPDATE {oQuery.DestinationTable} SET STATUS = 0" If oQuery.QueryConstraint <> String.Empty Then oResetSQL &= $" WHERE {oQuery.QueryConstraint}" End If _MSSQL.ExecuteNonQuery(oResetSQL) - _Logger.Info("Getting data for query [{0}]", oQuery.Name) + _Logger.Info("Getting data..", oQuery.Name) ' get the data from GraphQL Dim oDataResponse = oInterface.GetData(oQuery.QueryString, oQuery.OperationName) @@ -111,21 +115,21 @@ Public Class GraphQLJob Continue For End If - ' Finally delete all old records, when: - ' - ClearBeforeFill is true, which should be the last query for a given Operation - ' - QueryConstraint is not empty, which means the records produced by this query can be selected easily - If oQuery.ClearBeforeFill = True Or oQuery.QueryConstraint <> String.Empty Then - Dim oDeleteSQL = $"DELETE FROM {oQuery.DestinationTable} WHERE STATUS = 0" - If oQuery.QueryConstraint <> String.Empty Then - oDeleteSQL &= $" AND {oQuery.QueryConstraint}" - End If - _MSSQL.ExecuteNonQuery(oDeleteSQL) + ' Finally delete all old records + Dim oDeleteSQL = $"DELETE FROM {oQuery.DestinationTable} WHERE STATUS = 0" + If oQuery.QueryConstraint <> String.Empty Then + oDeleteSQL &= $" AND {oQuery.QueryConstraint}" End If + _Logger.Info("Success, deleting old records..", oQuery.Name) + _MSSQL.ExecuteNonQuery(oDeleteSQL) + Catch ex As Exception _Logger.Warn("Error while getting Data for Name/OperationName [{0}]/[{1}]", oQuery.Name, oQuery.OperationName) _Logger.Error(ex) + _Logger.Info("Failure, deleting new records..", oQuery.Name) + ' If a crash happens, delete all records which were inserted in this run, ' thus going back to the previous state Dim oDeleteSQL = $"DELETE FROM {oQuery.DestinationTable} WHERE STATUS = 1" @@ -133,6 +137,8 @@ Public Class GraphQLJob oDeleteSQL &= $" AND {oQuery.QueryConstraint}" End If _MSSQL.ExecuteNonQuery(oDeleteSQL) + Finally + _Logger.EndBlock() End Try Next @@ -172,13 +178,22 @@ Public Class GraphQLJob Dim oKeys As New List(Of String) For Each oMapping In QueryData.MappingFields - Dim oToken = oResultItem.SelectToken(oMapping.SourcePath) - - If oToken Is Nothing Then - _Logger.Warn("HandleResponse: Could not find value at SourcePath: {0}", oMapping.SourcePath) + Dim oValue As String = String.Empty + + If oMapping.SourcePath.StartsWith(PLACEHOLDER_STATIC) Then + 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 - oValues.Add(oToken.ToString()) + oValues.Add(oValue) oKeys.Add(oMapping.DestinationColumn) Next