From 24dcba902b06c2dd59618fb5af497e7d399e6dd6 Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 12 Dec 2019 09:59:11 +0800 Subject: [PATCH] Fix mongodb dashboard query bugs --- .../IClientSessionHandle.CAP.cs | 13 ++++++++++++- src/DotNetCore.CAP.MongoDB/IDataStorage.MongoDB.cs | 4 ++-- .../IMonitoringApi.MongoDB.cs | 14 +++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/DotNetCore.CAP.MongoDB/IClientSessionHandle.CAP.cs b/src/DotNetCore.CAP.MongoDB/IClientSessionHandle.CAP.cs index 82e5dce..177fb00 100644 --- a/src/DotNetCore.CAP.MongoDB/IClientSessionHandle.CAP.cs +++ b/src/DotNetCore.CAP.MongoDB/IClientSessionHandle.CAP.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Core Community. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using System; using System.Threading; using System.Threading.Tasks; using DotNetCore.CAP; @@ -18,7 +19,7 @@ namespace MongoDB.Driver public CapMongoDbClientSessionHandle(ICapTransaction transaction) { _transaction = transaction; - _sessionHandle = (IClientSessionHandle) _transaction.DbTransaction; + _sessionHandle = (IClientSessionHandle)_transaction.DbTransaction; } public void Dispose() @@ -76,5 +77,15 @@ namespace MongoDB.Driver { return _sessionHandle.Fork(); } + + public TResult WithTransaction(Func callback, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) + { + return _sessionHandle.WithTransaction(callback, transactionOptions, cancellationToken); + } + + public Task WithTransactionAsync(Func> callbackAsync, TransactionOptions transactionOptions = null, CancellationToken cancellationToken = default) + { + return _sessionHandle.WithTransactionAsync(callbackAsync, transactionOptions, cancellationToken); + } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP.MongoDB/IDataStorage.MongoDB.cs b/src/DotNetCore.CAP.MongoDB/IDataStorage.MongoDB.cs index dfa108e..e0de7ad 100644 --- a/src/DotNetCore.CAP.MongoDB/IDataStorage.MongoDB.cs +++ b/src/DotNetCore.CAP.MongoDB/IDataStorage.MongoDB.cs @@ -52,7 +52,7 @@ namespace DotNetCore.CAP.MongoDB public async Task ChangeReceiveStateAsync(MediumMessage message, StatusName state) { - var collection = _database.GetCollection(_options.Value.PublishedCollection); + var collection = _database.GetCollection(_options.Value.ReceivedCollection); var updateDef = Builders.Update .Set(x => x.Retries, message.Retries) @@ -161,7 +161,7 @@ namespace DotNetCore.CAP.MongoDB { if (collection == _options.Value.PublishedCollection) { - Builders.Filter.Lt(x => x.ExpiresAt, timeout); + //Builders.Filter.Lt(x => x.ExpiresAt, timeout); var publishedCollection = _database.GetCollection(_options.Value.PublishedCollection); var ret = await publishedCollection.DeleteManyAsync(x => x.ExpiresAt < timeout, cancellationToken); diff --git a/src/DotNetCore.CAP.MongoDB/IMonitoringApi.MongoDB.cs b/src/DotNetCore.CAP.MongoDB/IMonitoringApi.MongoDB.cs index 532c90e..0b7383f 100644 --- a/src/DotNetCore.CAP.MongoDB/IMonitoringApi.MongoDB.cs +++ b/src/DotNetCore.CAP.MongoDB/IMonitoringApi.MongoDB.cs @@ -63,12 +63,12 @@ namespace DotNetCore.CAP.MongoDB var statistics = new StatisticsDto { PublishedSucceeded = - (int) publishedCollection.CountDocuments(x => x.StatusName == nameof(StatusName.Succeeded)), + (int)publishedCollection.CountDocuments(x => x.StatusName == nameof(StatusName.Succeeded)), PublishedFailed = - (int) publishedCollection.CountDocuments(x => x.StatusName == nameof(StatusName.Failed)), + (int)publishedCollection.CountDocuments(x => x.StatusName == nameof(StatusName.Failed)), ReceivedSucceeded = - (int) receivedCollection.CountDocuments(x => x.StatusName == nameof(StatusName.Succeeded)), - ReceivedFailed = (int) receivedCollection.CountDocuments(x => x.StatusName == nameof(StatusName.Failed)) + (int)receivedCollection.CountDocuments(x => x.StatusName == nameof(StatusName.Succeeded)), + ReceivedFailed = (int)receivedCollection.CountDocuments(x => x.StatusName == nameof(StatusName.Failed)) }; return statistics; } @@ -93,7 +93,7 @@ namespace DotNetCore.CAP.MongoDB var builder = Builders.Filter; var filter = builder.Empty; if (!string.IsNullOrEmpty(queryDto.StatusName)) - filter &= builder.Eq(x => x.StatusName, queryDto.StatusName); + filter &= builder.Where(x => x.StatusName.ToLower() == queryDto.StatusName); if (!string.IsNullOrEmpty(queryDto.Name)) filter &= builder.Eq(x => x.Name, queryDto.Name); @@ -135,7 +135,7 @@ namespace DotNetCore.CAP.MongoDB private int GetNumberOfMessage(string collectionName, string statusName) { var collection = _database.GetCollection(collectionName); - var count = collection.CountDocuments(new BsonDocument {{"StatusName", statusName}}); + var count = collection.CountDocuments(new BsonDocument { { "StatusName", statusName } }); return int.Parse(count.ToString()); } @@ -194,7 +194,7 @@ namespace DotNetCore.CAP.MongoDB } }; - var pipeline = new[] {match, groupby}; + var pipeline = new[] { match, groupby }; var collection = _database.GetCollection(collectionName); var result = collection.Aggregate(pipeline).ToList();