public async Task<Post> InsertAsync(Post newPost) { newPost.Id = new ObjectId(); newPost.DatePublished = DateTime.UtcNow; await _collection.InsertOneAsync(newPost); return newPost; }
public async Task IndexAsync(Post post) { // Use a circuit breaker to make the indexer operation more resistent against problems. // When this operation fails three times, we stop for a minute before trying again. await CircuitBreaker.ExecuteAsync(async () => { // Indexes the content in ElasticSearch in the weblog index. // Uses the post type mapping defined earlier. return await _client.IndexAsync(post, (indexSelector) => indexSelector.Index("weblog").Type("post")); }); }