-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added expiration of documents #2
base: master
Are you sure you want to change the base?
Conversation
src/NLog.Raven/RavenTarget.cs
Outdated
if (ExpirationOffsetInDays > 0) | ||
{ | ||
var expiry = DateTime.UtcNow.AddDays(ExpirationOffsetInDays); | ||
bulkInsert.Store(logEntry, new MetadataAsDictionary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could one make a single MetadataAsDictionary
-instance (outside the loop), and use the same instance for all logEntries?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now using one instance for all entries.
src/NLog.Raven/RavenTarget.cs
Outdated
var expiry = DateTime.UtcNow.AddDays(ExpirationOffsetInDays); | ||
bulkInsert.Store(logEntry, new MetadataAsDictionary | ||
{ | ||
new KeyValuePair<string, object>("@expires", expiry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use Constants.Documents.Metadata.Expires
instead of "@expires"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to available constant.
src/NLog.Raven/RavenTarget.cs
Outdated
/// <summary> | ||
/// Expiration date of document | ||
/// </summary> | ||
public int ExpirationOffsetInDays { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rename to ExpiryDays
? (Easier to spell) Or TimeToLiveDays
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed.
src/NLog.Raven.Tests/App.config
Outdated
@@ -9,7 +9,7 @@ | |||
</extensions> | |||
<targets> | |||
<target name="raven" xsi:type="BufferingWrapper" flushTimeout="7000"> | |||
<target xsi:type="Raven" IdType="Guid" CollectionName="LogEntries" Urls="http://ws-1:8080;Database=RavenNLog"> | |||
<target xsi:type="Raven" IdType="Guid" CollectionName="LogEntriesExpire" Urls="http://localhost:8080" Database="logs" ExpirationOffsetInDays="3"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename from ExpirationOffsetInDays
to new ExpiryDays
src/NLog.Raven/RavenTarget.cs
Outdated
@@ -122,11 +128,24 @@ protected override void Write(IList<AsyncLogEventInfo> logEvents) | |||
{ | |||
using (var bulkInsert = _documentStore.BulkInsert()) | |||
{ | |||
for (int i = 0; i < logEvents.Count; ++i) | |||
var expiry = DateTime.UtcNow.AddDays(ExpiryDays); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider doing this:
var expiryMetaData = ExpiryDays > 0 ? new MetadataAsDictionary
{
new KeyValuePair<string, object>(Constants.Documents.Metadata.Expires, DateTime.UtcNow.AddDays(ExpiryDays))
} : null;
src/NLog.Raven/RavenTarget.cs
Outdated
var logEntry = CreateLogEntry(logEvent); | ||
bulkInsert.Store(logEntry); | ||
if (ExpiryDays > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then use it like this:
if (expiryMetaData != null
{
bulkInsert.Store(logEntry, expirationMetadata);
}
else
{
bulkInsert.Store(logEntry);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it looks good. @kentcooper Ready for merge?
No description provided.