Example #1
0
        private void CheckConnection(RunnerConnectionType connectionType)
        {
            switch (connectionType)
            {
            case RunnerConnectionType.Generic:
                if (!_hasGenericConnection)
                {
                    throw new InvalidOperationException($"SetConnection {RunnerConnectionType.Generic}");
                }
                break;

            case RunnerConnectionType.JobRequest:
                if (!_hasRequestConnection)
                {
                    throw new InvalidOperationException($"SetConnection {RunnerConnectionType.JobRequest}");
                }
                break;

            case RunnerConnectionType.MessageQueue:
                if (!_hasMessageConnection)
                {
                    throw new InvalidOperationException($"SetConnection {RunnerConnectionType.MessageQueue}");
                }
                break;

            default:
                throw new NotSupportedException(connectionType.ToString());
            }
        }
Example #2
0
        public void SetConnectionTimeout(RunnerConnectionType connectionType, TimeSpan timeout)
        {
            Trace.Info($"Set {connectionType} VssConnection's timeout to {timeout.TotalSeconds} seconds.");
            switch (connectionType)
            {
            case RunnerConnectionType.JobRequest:
                _requestConnection.Settings.SendTimeout = timeout;
                break;

            case RunnerConnectionType.MessageQueue:
                _messageConnection.Settings.SendTimeout = timeout;
                break;

            case RunnerConnectionType.Generic:
                _genericConnection.Settings.SendTimeout = timeout;
                break;

            default:
                Trace.Error($"Unexpected connection type: {connectionType}.");
                break;
            }
        }
Example #3
0
        // Refresh connection is best effort. it should never throw exception
        public async Task RefreshConnectionAsync(RunnerConnectionType connectionType, TimeSpan timeout)
        {
            Trace.Info($"Refresh {connectionType} VssConnection to get on a different AFD node.");
            VssConnection newConnection = null;

            switch (connectionType)
            {
            case RunnerConnectionType.MessageQueue:
                try
                {
                    _hasMessageConnection = false;
                    newConnection         = await EstablishVssConnection(_messageConnection.Uri, _messageConnection.Credentials, timeout);

                    var client = newConnection.GetClient <TaskAgentHttpClient>();
                    _messageConnection      = newConnection;
                    _messageTaskAgentClient = client;
                }
                catch (Exception ex)
                {
                    Trace.Error($"Catch exception during reset {connectionType} connection.");
                    Trace.Error(ex);
                    newConnection?.Dispose();
                }
                finally
                {
                    _hasMessageConnection = true;
                }
                break;

            case RunnerConnectionType.JobRequest:
                try
                {
                    _hasRequestConnection = false;
                    newConnection         = await EstablishVssConnection(_requestConnection.Uri, _requestConnection.Credentials, timeout);

                    var client = newConnection.GetClient <TaskAgentHttpClient>();
                    _requestConnection      = newConnection;
                    _requestTaskAgentClient = client;
                }
                catch (Exception ex)
                {
                    Trace.Error($"Catch exception during reset {connectionType} connection.");
                    Trace.Error(ex);
                    newConnection?.Dispose();
                }
                finally
                {
                    _hasRequestConnection = true;
                }
                break;

            case RunnerConnectionType.Generic:
                try
                {
                    _hasGenericConnection = false;
                    newConnection         = await EstablishVssConnection(_genericConnection.Uri, _genericConnection.Credentials, timeout);

                    var client = newConnection.GetClient <TaskAgentHttpClient>();
                    _genericConnection      = newConnection;
                    _genericTaskAgentClient = client;
                }
                catch (Exception ex)
                {
                    Trace.Error($"Catch exception during reset {connectionType} connection.");
                    Trace.Error(ex);
                    newConnection?.Dispose();
                }
                finally
                {
                    _hasGenericConnection = true;
                }
                break;

            default:
                Trace.Error($"Unexpected connection type: {connectionType}.");
                break;
            }
        }