-
Notifications
You must be signed in to change notification settings - Fork 46
/
RavenAuditUnitOfWorkFactory.cs
42 lines (37 loc) · 1.89 KB
/
RavenAuditUnitOfWorkFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace ServiceControl.Audit.Persistence.RavenDB.UnitOfWork
{
using System;
using System.Threading;
using Persistence.UnitOfWork;
using Raven.Client.Documents.BulkInsert;
using RavenDB;
using ServiceControl.Audit.Persistence.RavenDB.CustomChecks;
class RavenAuditIngestionUnitOfWorkFactory : IAuditIngestionUnitOfWorkFactory
{
public RavenAuditIngestionUnitOfWorkFactory(IRavenDocumentStoreProvider documentStoreProvider, IRavenSessionProvider sessionProvider,
DatabaseConfiguration databaseConfiguration, CheckMinimumStorageRequiredForAuditIngestion.State customCheckState)
{
this.documentStoreProvider = documentStoreProvider;
this.sessionProvider = sessionProvider;
this.databaseConfiguration = databaseConfiguration;
this.customCheckState = customCheckState;
}
public IAuditIngestionUnitOfWork StartNew(int batchSize)
{
var timedCancellationSource = new CancellationTokenSource(databaseConfiguration.BulkInsertCommitTimeout);
var bulkInsert = documentStoreProvider.GetDocumentStore()
.BulkInsert(new BulkInsertOptions { SkipOverwriteIfUnchanged = true, }, timedCancellationSource.Token);
return new RavenAuditIngestionUnitOfWork(
bulkInsert, timedCancellationSource, databaseConfiguration.AuditRetentionPeriod, new RavenAttachmentsBodyStorage(sessionProvider, bulkInsert, databaseConfiguration.MaxBodySizeToStore)
);
}
public bool CanIngestMore()
{
return customCheckState.CanIngestMore;
}
readonly IRavenDocumentStoreProvider documentStoreProvider;
readonly IRavenSessionProvider sessionProvider;
readonly DatabaseConfiguration databaseConfiguration;
readonly CheckMinimumStorageRequiredForAuditIngestion.State customCheckState;
}
}