Skip to content

Commit 8086607

Browse files
committed
creatopt update
1 parent d93986f commit 8086607

File tree

2 files changed

+26
-34
lines changed

2 files changed

+26
-34
lines changed

samples/ScheduleDemo/Program.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@
7272
}
7373

7474
// Create schedule options that runs every 4 seconds
75-
ScheduleCreationOptions scheduleOptions = new ScheduleCreationOptions
75+
ScheduleCreationOptions scheduleOptions = new ScheduleCreationOptions("demo-schedule101", nameof(StockPriceOrchestrator), TimeSpan.FromSeconds(4))
7676
{
77-
OrchestrationName = nameof(StockPriceOrchestrator),
78-
ScheduleId = "demo-schedule101",
79-
Interval = TimeSpan.FromSeconds(4),
8077
StartAt = DateTimeOffset.UtcNow,
8178
OrchestrationInput = "MSFT"
8279
};

src/ScheduledTasks/Models/ScheduleCreationOptions.cs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,37 @@ namespace Microsoft.DurableTask.ScheduledTasks;
99
public record ScheduleCreationOptions
1010
{
1111
/// <summary>
12-
/// The interval of the schedule.
12+
/// Initializes a new instance of the <see cref="ScheduleCreationOptions"/> class.
1313
/// </summary>
14-
TimeSpan interval;
14+
/// <param name="scheduleId">The ID of the schedule, or null to generate one.</param>
15+
/// <param name="orchestrationName">The name of the orchestration to schedule.</param>
16+
/// <param name="interval">The time interval between schedule executions. Must be at least 1 second and cannot be negative.</param>
17+
public ScheduleCreationOptions(string scheduleId, string orchestrationName, TimeSpan interval)
18+
{
19+
this.ScheduleId = Check.NotNullOrEmpty(scheduleId, nameof(scheduleId));
20+
this.OrchestrationName = Check.NotNullOrEmpty(orchestrationName, nameof(orchestrationName));
21+
if (interval <= TimeSpan.Zero)
22+
{
23+
throw new ArgumentException("Interval must be positive", nameof(interval));
24+
}
25+
26+
if (interval.TotalSeconds < 1)
27+
{
28+
throw new ArgumentException("Interval must be at least 1 second", nameof(interval));
29+
}
1530

16-
string orchestrationName = string.Empty;
31+
this.Interval = interval;
32+
}
1733

1834
/// <summary>
1935
/// Gets the name of the orchestration function to schedule.
2036
/// </summary>
21-
public string OrchestrationName
22-
{
23-
get => this.orchestrationName;
24-
init => this.orchestrationName = Check.NotNullOrEmpty(value, nameof(value));
25-
}
37+
public string OrchestrationName { get; }
2638

2739
/// <summary>
28-
/// Gets the ID of the schedule, if not provided, default to a new GUID.
40+
/// Gets the ID of the schedule.
2941
/// </summary>
30-
public string ScheduleId { get; init; };
42+
public string ScheduleId { get; }
3143

3244
/// <summary>
3345
/// Gets the input to the orchestration function.
@@ -40,36 +52,19 @@ public string OrchestrationName
4052
public string? OrchestrationInstanceId { get; init; }
4153

4254
/// <summary>
43-
/// Gets the start time of the schedule.
55+
/// Gets the start time of the schedule. If not provided, default to the current time.
4456
/// </summary>
4557
public DateTimeOffset? StartAt { get; init; }
4658

4759
/// <summary>
48-
/// Gets the end time of the schedule.
60+
/// Gets the end time of the schedule. If not provided, schedule will run indefinitely.
4961
/// </summary>
5062
public DateTimeOffset? EndAt { get; init; }
5163

5264
/// <summary>
5365
/// Gets the interval of the schedule.
5466
/// </summary>
55-
public TimeSpan Interval
56-
{
57-
get => this.interval;
58-
init
59-
{
60-
if (value <= TimeSpan.Zero)
61-
{
62-
throw new ArgumentException("Interval must be positive", nameof(value));
63-
}
64-
65-
if (value.TotalSeconds < 1)
66-
{
67-
throw new ArgumentException("Interval must be at least 1 second", nameof(value));
68-
}
69-
70-
this.interval = value;
71-
}
72-
}
67+
public TimeSpan Interval { get; }
7368

7469
/// <summary>
7570
/// Gets a value indicating whether to start the schedule immediately if it is late. Default is false.

0 commit comments

Comments
 (0)