@@ -124,70 +124,65 @@ public IScheduleHandle GetScheduleHandle(string scheduleId)
124124 /// <inheritdoc/>
125125 public AsyncPageable < ScheduleDescription > ListSchedulesAsync ( ScheduleQuery ? filter = null )
126126 {
127- // TODO: map to entity query last modified from/to filters
128- EntityQuery query = new EntityQuery
129- {
130- InstanceIdStartsWith = filter ? . ScheduleIdPrefix ?? nameof ( Schedule ) ,
131- IncludeState = true ,
132- PageSize = filter ? . PageSize ?? ScheduleQuery . DefaultPageSize ,
133- ContinuationToken = filter ? . ContinuationToken ,
134- } ;
135-
136127 // Create an async pageable using the Pageable.Create helper
137- return Task . FromResult ( Pageable . Create ( async ( continuationToken , pageSize , cancellation ) =>
128+ return Pageable . Create ( async ( continuationToken , pageSize , cancellation ) =>
138129 {
139130 try
140131 {
141- List < ScheduleDescription > schedules = new List < ScheduleDescription > ( ) ;
132+ // TODO: map to entity query last modified from/to filters
133+ EntityQuery query = new EntityQuery
134+ {
135+ InstanceIdStartsWith = filter ? . ScheduleIdPrefix ?? nameof ( Schedule ) ,
136+ IncludeState = true ,
137+ PageSize = filter ? . PageSize ?? ScheduleQuery . DefaultPageSize ,
138+ ContinuationToken = continuationToken ,
139+ } ;
140+
141+ // Get one page of entities
142+ IAsyncEnumerable < Page < EntityMetadata < ScheduleState > > > entityPages =
143+ this . durableTaskClient . Entities . GetAllEntitiesAsync < ScheduleState > ( query ) . AsPages ( ) ;
142144
143- await foreach ( EntityMetadata < ScheduleState > metadata in this . durableTaskClient . Entities . GetAllEntitiesAsync < ScheduleState > ( query ) )
145+ await foreach ( Page < EntityMetadata < ScheduleState > > entityPage in entityPages )
144146 {
145- ScheduleState state = metadata . State ;
146-
147- // Skip if status filter is specified and doesn't match
148- if ( filter ? . Status . HasValue == true && state . Status != filter . Status . Value )
149- {
150- continue ;
151- }
152-
153- // Skip if created time filter is specified and doesn't match
154- if ( filter ? . CreatedFrom . HasValue == true && state . ScheduleCreatedAt <= filter . CreatedFrom )
155- {
156- continue ;
157- }
158-
159- if ( filter ? . CreatedTo . HasValue == true && state . ScheduleCreatedAt >= filter . CreatedTo )
160- {
161- continue ;
162- }
163-
164- ScheduleConfiguration config = state . ScheduleConfiguration ! ;
165-
166- schedules . Add ( new ScheduleDescription
167- {
168- ScheduleId = metadata . Id . Key ,
169- OrchestrationName = config . OrchestrationName ,
170- OrchestrationInput = config . OrchestrationInput ,
171- OrchestrationInstanceId = config . OrchestrationInstanceId ,
172- StartAt = config . StartAt ,
173- EndAt = config . EndAt ,
174- Interval = config . Interval ,
175- StartImmediatelyIfLate = config . StartImmediatelyIfLate ,
176- Status = state . Status ,
177- ExecutionToken = state . ExecutionToken ,
178- LastRunAt = state . LastRunAt ,
179- NextRunAt = state . NextRunAt ,
180- } ) ;
147+ List < ScheduleDescription > schedules = entityPage . Values
148+ . Where ( metadata =>
149+ ( ! filter ? . Status . HasValue ?? true || metadata . State . Status == filter . Status . Value ) &&
150+ ( filter ? . CreatedFrom . HasValue != true || metadata . State . ScheduleCreatedAt > filter . CreatedFrom ) &&
151+ ( filter ? . CreatedTo . HasValue != true || metadata . State . ScheduleCreatedAt < filter . CreatedTo ) )
152+ . Select ( metadata =>
153+ {
154+ ScheduleState state = metadata . State ;
155+ ScheduleConfiguration config = state . ScheduleConfiguration ! ;
156+ return new ScheduleDescription
157+ {
158+ ScheduleId = metadata . Id . Key ,
159+ OrchestrationName = config . OrchestrationName ,
160+ OrchestrationInput = config . OrchestrationInput ,
161+ OrchestrationInstanceId = config . OrchestrationInstanceId ,
162+ StartAt = config . StartAt ,
163+ EndAt = config . EndAt ,
164+ Interval = config . Interval ,
165+ StartImmediatelyIfLate = config . StartImmediatelyIfLate ,
166+ Status = state . Status ,
167+ ExecutionToken = state . ExecutionToken ,
168+ LastRunAt = state . LastRunAt ,
169+ NextRunAt = state . NextRunAt ,
170+ } ;
171+ } )
172+ . ToList ( ) ;
173+
174+ return new Page < ScheduleDescription > ( schedules , entityPage . ContinuationToken ) ;
181175 }
182176
183- return new Page < ScheduleDescription > ( schedules , continuationToken ) ;
177+ // Return empty page if no results
178+ return new Page < ScheduleDescription > ( new List < ScheduleDescription > ( ) , null ) ;
184179 }
185180 catch ( OperationCanceledException e )
186181 {
187182 throw new OperationCanceledException (
188183 $ "The { nameof ( this . ListSchedulesAsync ) } operation was canceled.", e , e . CancellationToken ) ;
189184 }
190- } ) ) ;
185+ } ) ;
191186 }
192187
193188 /// <summary>
0 commit comments