public async Task IndexAllDocumentsJob(string userName, string notificationId, IndexingOptions[] options, IJobCancellationToken cancellationToken) { await WithInterceptorsAsync(options, async o => { try { if (await RunIndexJobAsync(userName, notificationId, false, o, IndexAllDocumentsAsync, cancellationToken)) { // Indexation manager might re-use the jobs to scale out indexation. // Wait for all indexing jobs to complete, before telling interceptors we're ready. // This method is running as a job as well, so skip this job. // Scale out background indexation jobs are scheduled as low. await WaitForIndexationJobsToBeReadyAsync(JobPriority.Low, x => x.Method != _manualIndexAllJobMethod && x.Method != _indexChangesJobMethod); } } finally { // Report indexation summary _progressHandler.Finish(); } }); }
private async Task IndexAsync(string currentUserName, string notificationId, bool suppressInsignificantNotifications, IEnumerable <IndexingOptions> allOptions, Func <IndexingOptions, CancellationToken, Task> indexationFunc) { // Reset progress handler to initial state _progressHandler.Start(currentUserName, notificationId, suppressInsignificantNotifications); // Capture the syncronization object (cancelation token source) if it is not captured already. var cancellationTokenSource = StartIndexation(); if (cancellationTokenSource == null) { // Report error and exit _progressHandler.AlreadyInProgress(); } else { // Begin indexation try { foreach (var options in allOptions) { await indexationFunc(options, cancellationTokenSource.Token); } } catch (OperationCanceledException) { _progressHandler.Cancel(); } catch (Exception ex) { _progressHandler.Exception(ex); } finally { // Report indexation summary _progressHandler.Finish(); // Release the syncronization object FinishIndexation(); } } }