/// <inheritdoc />
        public IEnumerable <int> Handle(FindExpiredMessagesToDeleteQuery <int> query)
        {
            if (query.Cancellation.IsCancellationRequested)
            {
                return(Enumerable.Empty <int>());
            }

            using (var db = _connectionInformation.GetDatabase())
            {
                //before executing a query, double check that we aren't stopping
                if (query.Cancellation.IsCancellationRequested)
                {
                    return(Enumerable.Empty <int>());
                }

                var col = db.Database.GetCollection <Schema.MetaDataTable>(_tableNameHelper.MetaDataName);

                var results = col.Query()
                              .Where(x => x.ExpirationTime < DateTime.UtcNow)
                              .ToList();

                var data = new List <int>(results.Count);
                foreach (var record in results)
                {
                    data.Add(record.QueueId);
                }

                return(data);
            }
        }
 public void Create_Default()
 {
     using (var cancel = new CancellationTokenSource())
     {
         var test = new FindExpiredMessagesToDeleteQuery(cancel.Token);
         Assert.Equal(cancel.Token, test.Cancellation);
     }
 }
예제 #3
0
 public void Create_Default()
 {
     using (var cancel = new CancellationTokenSource())
     {
         var test = new FindExpiredMessagesToDeleteQuery <long>(cancel.Token);
         Assert.Equal(cancel.Token, test.Cancellation);
     }
 }
예제 #4
0
        /// <summary>
        /// Handles the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="dbCommand">The database command.</param>
        /// <param name="commandType">Type of the command.</param>
        public void Handle(FindExpiredMessagesToDeleteQuery <long> query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var command = (NpgsqlCommand)dbCommand;

            command.Parameters.Add("@CurrentDate", NpgsqlDbType.Bigint);
            command.Parameters["@CurrentDate"].Value = _getTime.GetCurrentUtcDate().Ticks;
        }
        /// <summary>
        /// Handles the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="dbCommand">The database command.</param>
        /// <param name="commandType">Type of the command.</param>
        public void Handle(FindExpiredMessagesToDeleteQuery <long> query, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var command = dbCommand;
            var param   = command.CreateParameter();

            param.ParameterName = "@CurrentDateTime";
            param.DbType        = DbType.Int64;
            param.Value         = _getTime.GetCurrentUtcDate().Ticks;
            command.Parameters.Add(param);
        }
 public IEnumerable <long> Handle(FindExpiredMessagesToDeleteQuery <long> query)
 {
     try
     {
         return(_decorated.Handle(query));
     }
     catch (Exception e)
     {
         if (e.Message.IndexOf("abort due to ROLLBACK", StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             _logger.LogWarning($"The query has been aborted{System.Environment.NewLine}{e}");
             return(Enumerable.Empty <long>());
         }
         else
         {
             throw;
         }
     }
 }
 public IEnumerable <long> Handle(FindExpiredMessagesToDeleteQuery query)
 {
     try
     {
         return(_decorated.Handle(query));
     }
     catch (Exception e)
     {
         if (e.Message.IndexOf("abort due to ROLLBACK", StringComparison.InvariantCultureIgnoreCase) >= 0)
         {
             _logger.WarnException("The query has been aborted", e);
             return(Enumerable.Empty <long>());
         }
         else
         {
             throw;
         }
     }
 }
예제 #8
0
        public IEnumerable <T> Handle(FindExpiredMessagesToDeleteQuery <T> query)
        {
            if (query.Cancellation.IsCancellationRequested)
            {
                return(Enumerable.Empty <T>());
            }

            var results     = new List <T>();
            var commandType = _options.Value.EnableStatus
                ? CommandStringTypes.FindExpiredRecordsWithStatusToDelete
                : CommandStringTypes.FindExpiredRecordsToDelete;

            using (var connection = _dbConnectionFactory.Create())
            {
                connection.Open();

                //before executing a query, double check that we aren't stopping
                //otherwise, there is a chance that the tables no longer exist in memory mode
                if (query.Cancellation.IsCancellationRequested)
                {
                    return(Enumerable.Empty <T>());
                }

                using (var command = connection.CreateCommand())
                {
                    _prepareQuery.Handle(query, command, commandType);
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            if (query.Cancellation.IsCancellationRequested)
                            {
                                break;
                            }
                            results.Add(_readColumn.ReadAsType <T>(commandType, 0, reader));
                        }
                    }
                }
            }
            return(results);
        }
예제 #9
0
 /// <summary>
 /// Handles the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <long> Handle(FindExpiredMessagesToDeleteQuery query)
 {
     return(!_databaseExists.Exists(_connectionInformation.ConnectionString) ? Enumerable.Empty <long>() : _decorated.Handle(query));
 }
예제 #10
0
 /// <inheritdoc />
 public void Handle(FindExpiredMessagesToDeleteQuery <T> query, IDbCommand dbCommand, CommandStringTypes commandType)
 {
     dbCommand.CommandText = _commandCache.GetCommand(commandType);
 }