private async Task processAction(IMessagingAction action)
        {
            if (_options.Cancellation.IsCancellationRequested)
            {
                return;
            }

            await tryRestartConnection();

            // Something is wrong, but we'll keep trying in a bit
            if (!_storage.Session.IsConnected())
            {
                return;
            }

            try
            {
                try
                {
                    _trace.LogDebug("Running " + action.Description);
                    await action.Execute(_storage, this);
                }
                catch (Exception e)
                {
                    Logger.LogException(e, message: "Running " + action.Description);
                }
            }
            catch (Exception e)
            {
                Logger.LogException(e, message: "Error trying to run " + action);
                await _storage.Session.ReleaseNodeLock(_options.UniqueNodeId);
            }

            await _storage.Session.GetNodeLock(_options.UniqueNodeId);
        }
Beispiel #2
0
        public DurabilityAgent(ITransportLogger logger,
                               ILogger <DurabilityAgent> trace,
                               IWorkerQueue workers,
                               IEnvelopePersistence persistence,
                               ITransportRuntime runtime,
                               AdvancedSettings settings)
        {
            if (persistence is NulloEnvelopePersistence)
            {
                _disabled = true;
                return;
            }

            Logger       = logger;
            _trace       = trace;
            _workers     = workers;
            _persistence = persistence;
            _settings    = settings;


            _storage = _persistence.AgentStorage;

            _worker = new ActionBlock <IMessagingAction>(processAction, new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 1,
                CancellationToken      = _settings.Cancellation
            });

            NodeId = _settings.UniqueNodeId;

            IncomingMessages = new RecoverIncomingMessages(persistence, workers, settings, logger);
            OutgoingMessages = new RecoverOutgoingMessages(runtime, settings, logger);
            NodeReassignment = new NodeReassignment(settings);
            ScheduledJobs    = new RunScheduledJobs(settings, logger);
        }
        // This was built mostly for testing
        public Task Execute(IMessagingAction action)
        {
            if (_hasStarted)
            {
                var wrapper = new MessageActionWrapper(action);
                _worker.Post(wrapper);

                return(wrapper.Completion);
            }
            else
            {
                return(processAction(action));
            }
        }
Beispiel #4
0
        // This was built mostly for testing
        public Task Execute(IMessagingAction action)
        {
            // this is a side effect of the agent being shut down
            if (action == null)
            {
                return(Task.CompletedTask);
            }

            if (_hasStarted)
            {
                var wrapper = new MessageActionWrapper(action);
                _worker.Post(wrapper);

                return(wrapper.Completion);
            }
            else
            {
                return(processAction(action));
            }
        }
        public DurabilityAgent(JasperOptions options,
                               ITransportLogger logger,
                               ILogger <DurabilityAgent> trace,
                               IWorkerQueue workers,
                               IEnvelopePersistence persistence,
                               ISubscriberGraph subscribers)
        {
            if (persistence is NulloEnvelopePersistence)
            {
                _disabled = true;
                return;
            }

            options.DurabilityAgent = this;

            _options     = options;
            Logger       = logger;
            _trace       = trace;
            _workers     = workers;
            _persistence = persistence;



            _storage = _persistence.AgentStorage;

            _worker = new ActionBlock <IMessagingAction>(processAction, new ExecutionDataflowBlockOptions
            {
                MaxDegreeOfParallelism = 1,
                CancellationToken      = _options.Cancellation
            });

            NodeId = _options.UniqueNodeId;

            IncomingMessages = new RecoverIncomingMessages(workers, options, logger);
            OutgoingMessages = new RecoverOutgoingMessages(subscribers, options, logger);
            NodeReassignment = new NodeReassignment(options, logger);
            ScheduledJobs    = new RunScheduledJobs(options, logger);
        }
Beispiel #6
0
        private async Task processAction(IMessagingAction action)
        {
            await tryRestartConnection();

            if (_connection == null)
            {
                return;
            }

            var tx = _connection.BeginTransaction();

            var session = _store.OpenSession(new SessionOptions
            {
                Connection  = _connection,
                Transaction = tx,
                Tracking    = DocumentTracking.None
            });

            try
            {
                await action.Execute(session);
            }
            catch (Exception e)
            {
                _logger.LogException(e);
            }
            finally
            {
                if (!tx.IsCompleted)
                {
                    await tx.RollbackAsync();
                }

                session.Dispose();
            }

            await tryRestartConnection();
        }
 public MessageActionWrapper(IMessagingAction inner)
 {
     _inner      = inner;
     _completion = new TaskCompletionSource <bool>();
 }