Exemplo n.º 1
0
        public async ValueTask <int> StageBatch(IReadOnlyList <TimeoutData> timeouts, int batchNumber)
        {
            await MsmqQueueCreator.TruncateTable(connection, MsmqSqlConstants.TimeoutMigrationStagingTable, schema, databaseName);

            foreach (var timeout in timeouts)
            {
                stagingDataTable.Rows.Add(timeout.Id, timeout.Destination, timeout.State, timeout.Time, SerializeHeaders(timeout.Headers));
            }

            await using var transaction = (SqlTransaction) await connection.BeginTransactionAsync();

            using var sqlBulk = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction)
                  {
                      DestinationTableName = MsmqSqlConstants.TimeoutMigrationStagingTable,
                  };
            try
            {
                await sqlBulk.WriteToServerAsync(stagingDataTable);

                await transaction.CommitAsync();
            }
            catch (Exception e)
            {
                logger.LogError(e, $"Unable to bulk copy batch '{batchNumber}' to the staging table. Exception occured: {e.Message}");
                return(0);
            }
            finally
            {
                stagingDataTable.Clear();
            }

            return(timeouts.Count);
        }
Exemplo n.º 2
0
 async ValueTask EnsureMigrationTableExists()
 {
     try
     {
         await MsmqQueueCreator.CreateStagingQueue(connection, MsmqSqlConstants.TimeoutMigrationStagingTable, schema, connection.Database, preview : false);
     }
     catch (Exception e)
     {
         logger.LogError($"Unable to create the staging queue '{MsmqSqlConstants.TimeoutMigrationStagingTable}'. The following exception occured: {e.Message}");
         throw;
     }
 }
Exemplo n.º 3
0
        public async ValueTask <MigrationCheckResult> AbleToMigrate(EndpointInfo endpoint)
        {
            var migrationCheckResult = new MigrationCheckResult();

            try
            {
                await EnsureConnectionOpen();
            }
            catch (Exception e)
            {
                migrationCheckResult.Problems.Add($"Unable to connect to the server or database using the provided connection string. Verify the connection string. The following exception occured: {e.Message}");
                return(migrationCheckResult);
            }

            var databaseName = connection.Database;

            try
            {
                await MsmqQueueCreator.CreateStagingQueue(connection, MsmqSqlConstants.TimeoutMigrationStagingTable, schema, databaseName, preview : true);
            }
            catch (Exception e)
            {
                migrationCheckResult.Problems.Add($"Attempt to verify whether the timeout migration staging table '{MsmqSqlConstants.TimeoutMigrationStagingTable}' could be created during migration mode failed. The following exception occured: {e.Message}");
            }

            var endpointDelayedTableName = MsmqSqlConstants.DelayedTableName(endpoint.EndpointName);

            if (!await MsmqQueueCreator
                .DoesDelayedDeliveryTableExist(connection, endpointDelayedTableName, schema, databaseName)
                .ConfigureAwait(false))
            {
                migrationCheckResult.Problems.Add($"Could not find delayed queue table with name '{endpointDelayedTableName}' for the endpoint '{endpoint.EndpointName}'");
            }

            return(migrationCheckResult);
        }
Exemplo n.º 4
0
 Task RemoveMigrationTable()
 {
     return(MsmqQueueCreator.DeleteStagingQueue(connection, MsmqSqlConstants.TimeoutMigrationStagingTable, schema, connection.Database));
 }
Exemplo n.º 5
0
 public async ValueTask <int> CompleteBatch(int batchNumber)
 {
     return(await MsmqQueueCreator.MoveFromTo(connection, MsmqSqlConstants.TimeoutMigrationStagingTable, schema, endpointDelayedTableName, schema, databaseName));
 }