-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathRavenAuditUnitOfWorkFactory.cs
More file actions
30 lines (27 loc) · 1.43 KB
/
RavenAuditUnitOfWorkFactory.cs
File metadata and controls
30 lines (27 loc) · 1.43 KB
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
namespace ServiceControl.Audit.Persistence.RavenDB.UnitOfWork
{
using System.Threading;
using System.Threading.Tasks;
using Persistence.UnitOfWork;
using Raven.Client.Documents.BulkInsert;
using RavenDB;
class RavenAuditIngestionUnitOfWorkFactory(
IRavenDocumentStoreProvider documentStoreProvider,
IRavenSessionProvider sessionProvider,
DatabaseConfiguration databaseConfiguration,
MinimumRequiredStorageState customCheckState)
: IAuditIngestionUnitOfWorkFactory
{
public async ValueTask<IAuditIngestionUnitOfWork> StartNew(int batchSize, CancellationToken cancellationToken)
{
var timedCancellationSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
timedCancellationSource.CancelAfter(databaseConfiguration.BulkInsertCommitTimeout);
var bulkInsert = (await documentStoreProvider.GetDocumentStore(timedCancellationSource.Token))
.BulkInsert(new BulkInsertOptions { SkipOverwriteIfUnchanged = true, }, timedCancellationSource.Token);
return new RavenAuditIngestionUnitOfWork(
bulkInsert, timedCancellationSource, databaseConfiguration.AuditRetentionPeriod, new RavenAttachmentsBodyStorage(sessionProvider, bulkInsert, databaseConfiguration.MaxBodySizeToStore)
);
}
public bool CanIngestMore() => customCheckState.CanIngestMore;
}
}