Files
git.stella-ops.org/src/Graph/StellaOps.Graph.Indexer/Incremental/MongoIdempotencyStore.cs
StellaOps Bot dc7c75b496
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
feat: Add MongoIdempotencyStoreOptions for MongoDB configuration
feat: Implement BsonJsonConverter for converting BsonDocument and BsonArray to JSON

fix: Update project file to include MongoDB.Bson package

test: Add GraphOverlayExporterTests to validate NDJSON export functionality

refactor: Refactor Program.cs in Attestation Tool for improved argument parsing and error handling

docs: Update README for stella-forensic-verify with usage instructions and exit codes

feat: Enhance HmacVerifier with clock skew and not-after checks

feat: Add MerkleRootVerifier and ChainOfCustodyVerifier for additional verification methods

fix: Update DenoRuntimeShim to correctly handle file paths

feat: Introduce ComposerAutoloadData and related parsing in ComposerLockReader

test: Add tests for Deno runtime execution and verification

test: Enhance PHP package tests to include autoload data verification

test: Add unit tests for HmacVerifier and verification logic
2025-11-22 16:42:56 +02:00

35 lines
1.4 KiB
C#

using MongoDB.Bson;
using MongoDB.Driver;
namespace StellaOps.Graph.Indexer.Incremental;
public sealed class MongoIdempotencyStore : IIdempotencyStore
{
private readonly IMongoCollection<BsonDocument> _collection;
public MongoIdempotencyStore(IMongoDatabase database, MongoIdempotencyStoreOptions? options = null)
{
ArgumentNullException.ThrowIfNull(database);
var resolved = options ?? new MongoIdempotencyStoreOptions();
_collection = database.GetCollection<BsonDocument>(resolved.CollectionName);
}
public async Task<bool> HasSeenAsync(string sequenceToken, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var filter = Builders<BsonDocument>.Filter.Eq("sequence_token", sequenceToken);
return await _collection.Find(filter).AnyAsync(cancellationToken).ConfigureAwait(false);
}
public async Task MarkSeenAsync(string sequenceToken, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
var filter = Builders<BsonDocument>.Filter.Eq("sequence_token", sequenceToken);
var update = Builders<BsonDocument>.Update.Set("sequence_token", sequenceToken)
.SetOnInsert("recorded_at", DateTimeOffset.UtcNow.UtcDateTime);
await _collection.UpdateOneAsync(filter, update, new UpdateOptions { IsUpsert = true }, cancellationToken)
.ConfigureAwait(false);
}
}