public override async Task UpdateWithResults(RatedComment comment, WatsonResponse watsonResponse) { var cacheClearTask = ClearFromCache(comment); var dbUpdateTask = base.UpdateWithResults(comment, watsonResponse); _logger.LogInformation($"Message id {comment.UniqueID} updating flushing from cache"); await Task.WhenAll(cacheClearTask, dbUpdateTask); }
public override async Task UpdateAsFailure(RatedComment comment) { var cacheClearTask = ClearFromCache(comment); var dbUpdateTask = base.UpdateAsFailure(comment); _logger.LogInformation($"Message id {comment.UniqueID} updating flushing from cache"); await Task.WhenAll(cacheClearTask, dbUpdateTask); }
private async Task ClearFromCache(RatedComment ratedComment) { try { await Database.KeyDeleteAsync(ratedComment.UniqueID.ToString()); } catch (Exception ex) { _logger.LogError(ex, "Error clearing item from cache"); } }
private async Task AddToCache(RatedComment ratedComment) { try { _logger.LogInformation($"Message id {ratedComment.UniqueID} added to cache"); await Database.StringSetAsync(ratedComment.UniqueID.ToString(), JsonSerializer.Serialize(ratedComment)); } catch (Exception ex) { _logger.LogError(ex, "Error occured reading from cache"); } }
public async Task <RatedComment> CreateAndStoreMessage(string message) { var ratedMessage = new RatedComment() { Message = message }; await _mongoCollection.Value.InsertOneAsync(ratedMessage); _logger.LogInformation($"Uploaded comment stored in Mongo ID - {ratedMessage.UniqueID}"); return(ratedMessage); }
public virtual async Task UpdateAsFailure(RatedComment comment) { var filter = Builders <RatedComment> .Filter.Eq(AppConstants.DbKeyField, comment.UniqueID); var updates = Builders <RatedComment> .Update.Combine(new[] { Builders <RatedComment> .Update.Set(AppConstants.WatsonStatusField, ResponseStatus.Failed) }); await _mongoCollection.Value.UpdateOneAsync(filter, updates); _logger.LogInformation($"Document ID - {comment.UniqueID}, updated as failure"); }
public virtual async Task UpdateWithResults(RatedComment comment, WatsonResponse watsonResponse) { var filter = Builders <RatedComment> .Filter.Eq(AppConstants.DbKeyField, comment.UniqueID); var updates = Builders <RatedComment> .Update.Combine(new[] { Builders <RatedComment> .Update.Set(AppConstants.WatsonResponseField, watsonResponse), Builders <RatedComment> .Update.Set(AppConstants.WatsonStatusField, ResponseStatus.Complete) }); await _mongoCollection.Value.UpdateOneAsync(filter, updates); _logger.LogInformation($"Document ID - {comment.UniqueID}, updated with watson results"); }