Skip to content
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

add property to set 'WithStartTime' on change feed #381

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,31 @@ internal ChangeFeedOptions(Type itemType)
/// </summary>
public string ProcessorName { get; set; } = "cosmos-repository-pattern-processor";

private DateTime? _startTime;

/// <summary>
/// Sets the time (exclusive) to start looking for changes after.
/// </summary>
/// <remarks>
/// This is only used when:
/// (1) Lease store is not initialized and is ignored if a lease exists and has continuation token.
/// (2) StartContinuation is not specified.
/// If this is specified, StartFromBeginning is ignored.
/// </remarks>
public DateTime? StartTime
{
get => _startTime;
set
{
if (value.HasValue && value.Value.Kind != DateTimeKind.Utc)
throw new ArgumentOutOfRangeException(nameof(value),"StartTime must be Utc");
_startTime = value;
}
}

internal bool IsTheSameAs(ChangeFeedOptions? options) =>
options?.InstanceName == InstanceName &&
options?.PollInterval == PollInterval &&
options?.ProcessorName == ProcessorName;
}
options?.ProcessorName == ProcessorName &&
options?.StartTime == StartTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public async Task StartAsync()
builder.WithPollInterval(_changeFeedOptions.PollInterval.Value);
}

if (_changeFeedOptions.StartTime.HasValue)
{
builder.WithStartTime(_changeFeedOptions.StartTime.Value);
}
_processor = builder.Build();

_logger.LogInformation("Starting change feed processor for container {ContainerName}", itemContainer.Id);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) David Pine. All rights reserved.
// Licensed under the MIT License.

namespace Microsoft.Azure.CosmosRepositoryTests.ChangeFeed;

public class ChangeFeedOptionsTests
{
[Fact]
public void StarTime_Utc_SetsValue()
{
//Arrange
var startTime = new DateTime(2000, 1, 1, 0, 0,0, DateTimeKind.Utc);

//Act
var actual = new ChangeFeedOptions(typeof(object)) { StartTime = startTime };

//Assert
Assert.Equal(startTime, actual.StartTime);
}

[Fact]
public void StartTime_NotUtc_Throws()
{
//Arrange
var startTime = new DateTime(2000, 1, 1);

//Act
//Assert
Assert.Throws<ArgumentOutOfRangeException>(() => new ChangeFeedOptions(typeof(object)) { StartTime = startTime });
}

[Fact]
public void StartTime_Null_SetsValue()
{
//Arrange
//Act
var actual = new ChangeFeedOptions(typeof(object)) {StartTime = null};

//Assert
Assert.Null(actual.StartTime);
}
}