@@ -9,35 +9,46 @@ namespace Microsoft.DurableTask.ScheduledTasks;
99class ScheduleConfiguration
1010{
1111 string orchestrationName ;
12- TimeSpan ? interval ;
12+ TimeSpan interval ;
1313
1414 /// <summary>
1515 /// Initializes a new instance of the <see cref="ScheduleConfiguration"/> class.
1616 /// </summary>
17+ /// <param name="scheduleId">The ID of the schedule.</param>
1718 /// <param name="orchestrationName">The name of the orchestration to schedule.</param>
18- /// <param name="scheduleId">The ID of the schedule, or null to generate one.</param>
19- public ScheduleConfiguration ( string orchestrationName , string scheduleId )
19+ /// <param name="interval">The interval between schedule executions. Must be positive and at least 1 second.</param>
20+ #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
21+ public ScheduleConfiguration ( string scheduleId , string orchestrationName , TimeSpan interval )
22+ #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
2023 {
21- this . orchestrationName = Check . NotNullOrEmpty ( orchestrationName , nameof ( orchestrationName ) ) ;
22- this . ScheduleId = scheduleId ?? Guid . NewGuid ( ) . ToString ( "N" ) ;
24+ this . ScheduleId = Check . NotNullOrEmpty ( scheduleId , nameof ( scheduleId ) ) ;
25+ this . OrchestrationName = Check . NotNullOrEmpty ( orchestrationName , nameof ( orchestrationName ) ) ;
26+ if ( interval <= TimeSpan . Zero )
27+ {
28+ throw new ArgumentException ( "Interval must be positive" , nameof ( interval ) ) ;
29+ }
30+
31+ if ( interval . TotalSeconds < 1 )
32+ {
33+ throw new ArgumentException ( "Interval must be at least 1 second" , nameof ( interval ) ) ;
34+ }
35+
36+ this . Interval = interval ;
2337 }
2438
2539 /// <summary>
26- /// Gets or sets the name of the orchestration function to schedule.
40+ /// Gets or Sets the name of the orchestration function to schedule.
2741 /// </summary>
2842 public string OrchestrationName
2943 {
3044 get => this . orchestrationName ;
31- set
32- {
33- this . orchestrationName = Check . NotNullOrEmpty ( value , nameof ( value ) ) ;
34- }
45+ set => this . orchestrationName = Check . NotNullOrEmpty ( value , nameof ( this . OrchestrationName ) ) ;
3546 }
3647
3748 /// <summary>
3849 /// Gets the ID of the schedule.
3950 /// </summary>
40- public string ScheduleId { get ; init ; }
51+ public string ScheduleId { get ; }
4152
4253 /// <summary>
4354 /// Gets or sets the input to the orchestration function.
@@ -62,22 +73,17 @@ public string OrchestrationName
6273 /// <summary>
6374 /// Gets or sets the interval between schedule executions.
6475 /// </summary>
65- public TimeSpan ? Interval
76+ public TimeSpan Interval
6677 {
6778 get => this . interval ;
6879 set
6980 {
70- if ( ! value . HasValue )
71- {
72- return ;
73- }
74-
75- if ( value . Value <= TimeSpan . Zero )
81+ if ( value <= TimeSpan . Zero )
7682 {
7783 throw new ArgumentException ( "Interval must be positive" , nameof ( value ) ) ;
7884 }
7985
80- if ( value . Value . TotalSeconds < 1 )
86+ if ( value . TotalSeconds < 1 )
8187 {
8288 throw new ArgumentException ( "Interval must be at least 1 second" , nameof ( value ) ) ;
8389 }
@@ -98,13 +104,14 @@ public TimeSpan? Interval
98104 /// <returns>A new schedule configuration.</returns>
99105 public static ScheduleConfiguration FromCreateOptions ( ScheduleCreationOptions createOptions )
100106 {
101- return new ScheduleConfiguration ( createOptions . OrchestrationName , createOptions . ScheduleId )
107+ Check . NotNull ( createOptions , nameof ( createOptions ) ) ;
108+
109+ return new ScheduleConfiguration ( createOptions . ScheduleId , createOptions . OrchestrationName , createOptions . Interval )
102110 {
103111 OrchestrationInput = createOptions . OrchestrationInput ,
104112 OrchestrationInstanceId = createOptions . OrchestrationInstanceId ,
105113 StartAt = createOptions . StartAt ,
106114 EndAt = createOptions . EndAt ,
107- Interval = createOptions . Interval ,
108115 StartImmediatelyIfLate = createOptions . StartImmediatelyIfLate ,
109116 } ;
110117 }
@@ -151,7 +158,7 @@ public HashSet<string> Update(ScheduleUpdateOptions updateOptions)
151158
152159 if ( updateOptions . Interval . HasValue )
153160 {
154- this . Interval = updateOptions . Interval ;
161+ this . Interval = updateOptions . Interval . Value ;
155162 updatedFields . Add ( nameof ( this . Interval ) ) ;
156163 }
157164
0 commit comments