Ejemplo n.º 1
0
        /// <summary>
        /// Queries the underlying table and returns due timeouts, removing them at the same time
        /// </summary>
        public DueTimeoutsResult GetDueTimeouts()
        {
            var connection = new SqlConnection(connectionString);

            connection.Open();
            var transaction = connection.BeginTransaction();

            var dueTimeouts = new List <DueTimeout>();

            using (var command = connection.CreateCommand())
            {
                command.Transaction = transaction;
                command.CommandText =
                    string.Format(
                        @"
select 
    id, 
    time_to_return, 
    correlation_id, 
    saga_id, 
    reply_to, 
    custom_data 

from [{0}] with (updlock, readpast, rowlock)

where time_to_return <= @current_time 

order by time_to_return asc
",
                        timeoutsTableName);

                command.Parameters.AddWithValue("current_time", RebusTimeMachine.Now());

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var id            = (long)reader["id"];
                        var correlationId = (string)reader["correlation_id"];
                        var sagaId        = (Guid)reader["saga_id"];
                        var replyTo       = (string)reader["reply_to"];
                        var timeToReturn  = (DateTime)reader["time_to_return"];
                        var customData    = (string)(reader["custom_data"] != DBNull.Value ? reader["custom_data"] : "");

                        var sqlTimeout = new DueSqlTimeout(id, replyTo, correlationId, timeToReturn, sagaId, customData, timeoutsTableName, connection, transaction);

                        dueTimeouts.Add(sqlTimeout);
                    }
                }

                return(new DueTimeoutsResult(dueTimeouts, () =>
                {
                    transaction.Commit();
                    transaction.Dispose();
                    connection.Dispose();
                }));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Queries the underlying table and returns due timeouts, removing them at the same time
        /// </summary>
        public IEnumerable <DueTimeout> GetDueTimeouts()
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                var dueTimeouts = new List <DueTimeout>();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText =
                        string.Format(
                            @"select id, time_to_return, correlation_id, saga_id, reply_to, custom_data from [{0}] where time_to_return <= @current_time order by time_to_return asc",
                            timeoutsTableName);

                    command.Parameters.AddWithValue("current_time", RebusTimeMachine.Now());

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var id            = (long)reader["id"];
                            var correlationId = (string)reader["correlation_id"];
                            var sagaId        = (Guid)reader["saga_id"];
                            var replyTo       = (string)reader["reply_to"];
                            var timeToReturn  = (DateTime)reader["time_to_return"];
                            var customData    = (string)(reader["custom_data"] != DBNull.Value ? reader["custom_data"] : "");

                            var sqlTimeout = new DueSqlTimeout(id, replyTo, correlationId, timeToReturn, sagaId, customData, connectionString, timeoutsTableName);

                            dueTimeouts.Add(sqlTimeout);
                        }
                    }
                }

                return(dueTimeouts);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Queries the underlying table and returns due timeouts, removing them at the same time
        /// </summary>
        public DueTimeoutsResult GetDueTimeouts()
        {
            var connection = new SqlConnection(connectionString);
            connection.Open();
            var transaction = connection.BeginTransaction();

            var dueTimeouts = new List<DueTimeout>();

            using (var command = connection.CreateCommand())
            {
                command.Transaction = transaction;
                command.CommandText =
                    string.Format(
                        @"
select 
    id, 
    time_to_return, 
    correlation_id, 
    saga_id, 
    reply_to, 
    custom_data 

from [{0}] with (updlock, readpast, rowlock)

where time_to_return <= @current_time 

order by time_to_return asc
",
                        timeoutsTableName);

                command.Parameters.AddWithValue("current_time", RebusTimeMachine.Now());

                using (var reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var id = (long)reader["id"];
                        var correlationId = (string)reader["correlation_id"];
                        var sagaId = (Guid)reader["saga_id"];
                        var replyTo = (string)reader["reply_to"];
                        var timeToReturn = (DateTime)reader["time_to_return"];
                        var customData = (string)(reader["custom_data"] != DBNull.Value ? reader["custom_data"] : "");

                        var sqlTimeout = new DueSqlTimeout(id, replyTo, correlationId, timeToReturn, sagaId, customData, timeoutsTableName, connection, transaction);

                        dueTimeouts.Add(sqlTimeout);
                    }
                }

                return new DueTimeoutsResult(dueTimeouts, () =>
                {
                    transaction.Commit();
                    transaction.Dispose();
                    connection.Dispose();
                });
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Queries the underlying table and returns due timeouts, removing them at the same time
        /// </summary>
        public IEnumerable<DueTimeout> GetDueTimeouts()
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();

                var dueTimeouts = new List<DueTimeout>();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText =
                        string.Format(
                            @"select time_to_return, correlation_id, saga_id, reply_to, custom_data from [{0}] where time_to_return <= @current_time",
                            timeoutsTableName);

                    command.Parameters.AddWithValue("current_time", RebusTimeMachine.Now());

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var correlationId = (string)reader["correlation_id"];
                            var sagaId = (Guid)reader["saga_id"];
                            var replyTo = (string)reader["reply_to"];
                            var timeToReturn = (DateTime)reader["time_to_return"];
                            var customData = (string)(reader["custom_data"] != DBNull.Value ? reader["custom_data"] : "");

                            var sqlTimeout = new DueSqlTimeout(replyTo, correlationId, timeToReturn, sagaId, customData, connectionString, timeoutsTableName);

                            dueTimeouts.Add(sqlTimeout);
                        }
                    }

                }

                return dueTimeouts;
            }
        }