Пример #1
0
        public override void OnAfterRepositoryStart(RepositoryInstance repository)
        {
            var state = DistributedIndexingActivityQueue.GetCurrentState();

            DistributedIndexingActivityQueue._setCurrentExecutionState(IndexingActivityStatus.Startup);
            base.OnAfterRepositoryStart(repository);
        }
        /// <summary>
        /// Executes the activity's main action.
        /// </summary>
        /// <param name="onRemote">True if the caller is a message receiver.</param>
        /// <param name="isFromMe">True if the source of the activity is in the current appDomain.</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A Task that represents the asynchronous operation.</returns>
        public override async STT.Task DoActionAsync(bool onRemote, bool isFromMe, CancellationToken cancellationToken)
        {
            if (!IndexManager.Running)
            {
                return;
            }

            if (onRemote && !isFromMe)
            {
                //TODO: Remove unnecessary inheritance steps.
                if (this is IndexingActivityBase indexingActivity)
                {
                    // We can drop activities here because the queue will load these from the database
                    // anyway when it processed all the previous activities.
                    if (DistributedIndexingActivityQueue.IsOverloaded())
                    {
                        SnTrace.Index.Write("IAQ OVERLOAD drop activity FromReceiver A:" + indexingActivity.Id);
                        return;
                    }

                    indexingActivity.FromReceiver = true;

                    DistributedIndexingActivityQueue.ExecuteActivity(indexingActivity);
                }
                else
                {
                    await InternalExecuteIndexingActivityAsync(cancellationToken).ConfigureAwait(false);
                }
            }
        }
        /// <summary>
        /// Waits for a release signal that indicates that this activity has been executed
        /// successfully in the background.
        /// </summary>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>A Task that represents the asynchronous operation.</returns>
        public async STT.Task WaitForCompleteAsync(CancellationToken cancellationToken)
        {
            if (_finished)
            {
                return;
            }

            _waitingThreadId = Thread.CurrentThread.ManagedThreadId;

            var indexingActivity = this as IndexingActivityBase;

            SnTrace.IndexQueue.Write("IAQ: A{0} blocks the T{1}", indexingActivity?.Id, _waitingThreadId);

            if (Debugger.IsAttached)
            {
                // in debug mode wait without a timeout
                await _finishSignal.WaitAsync(cancellationToken).ConfigureAwait(false);
            }
            else
            {
                try
                {
                    var timeOut = TimeSpan.FromSeconds(Configuration.Indexing.IndexingActivityTimeoutInSeconds);

                    await _finishSignal.WaitAsync(cancellationToken.AddTimeout(timeOut)).ConfigureAwait(false);
                }
                catch (OperationCanceledException)
                {
                    var message = indexingActivity != null
                        ? $"IndexingActivity is timed out. Id: {indexingActivity.Id}, Type: {indexingActivity.ActivityType}. Max task id and exceptions: {DistributedIndexingActivityQueue.GetCurrentCompletionState()}"
                        : "Activity is not finishing on a timely manner";

                    throw new ApplicationException(message);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Waits for a release signal that indicates that this activity has been executed
        /// successfully in the background.
        /// </summary>
        public void WaitForComplete()
        {
            if (_finished)
            {
                return;
            }

            _waitingThreadId = Thread.CurrentThread.ManagedThreadId;

            var indexingActivity = this as IndexingActivityBase;

            SnTrace.IndexQueue.Write("IAQ: A{0} blocks the T{1}", indexingActivity?.Id, _waitingThreadId);

            if (Debugger.IsAttached)
            {
                _finishSignal.WaitOne();
            }
            else
            {
                if (!_finishSignal.WaitOne(Configuration.Indexing.IndexingActivityTimeoutInSeconds * 1000, false))
                {
                    var message = indexingActivity != null
                        ? $"IndexingActivity is timed out. Id: {indexingActivity.Id}, Type: {indexingActivity.ActivityType}. Max task id and exceptions: {DistributedIndexingActivityQueue.GetCurrentCompletionState()}"
                        : "Activity is not finishing on a timely manner";

                    throw new ApplicationException(message);
                }
            }
        }