コード例 #1
0
        /// <summary>
        /// Queries the underlying table and returns due timeouts, removing them at the same time
        /// </summary>
        public DueTimeoutsResult GetDueTimeouts()
        {
            var dueTimeouts = new List <DueTimeout>();

            using (var connection = factory.OpenConnection())
                using (var command = connection.CreateCommand())
                {
                    const string sql = @"
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
";

                    command.CommandText = string.Format(sql, timeoutsTableName);

                    command.AddParameter("current_time", RebusTimeMachine.Now());

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var sqlTimeout = DueAdoNetTimeout.Create(MarkAsProcessed, timeoutsTableName, reader);

                            dueTimeouts.Add(sqlTimeout);
                        }
                    }
                }

            return(new DueTimeoutsResult(dueTimeouts));
        }
コード例 #2
0
        /// <summary>
        /// Queries the underlying table and returns due timeouts, removing them at the same time
        /// </summary>
        public DueTimeoutsResult GetDueTimeouts()
        {
            var            dueTimeouts = new List <DueTimeout>();
            IDbConnection  connection  = null;
            IDbTransaction transaction = null;

            try
            {
                connection  = factory.OpenConnection();
                transaction = connection.BeginTransaction();

                using (var command = connection.CreateCommand())
                {
                    command.Transaction = transaction;
                    command.CommandText = FormatGetTimeoutsDueQuery(dialect, timeoutsTableName, batchSize);
                    command.AddParameter("current_time", RebusTimeMachine.Now());

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var sqlTimeout = DueAdoNetTimeout.Create(connection, timeoutsTableName, reader);

                            dueTimeouts.Add(sqlTimeout);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("GetDueTimeout produced an exception: {0}", ex);

                SafeDispose(transaction, "Disposing the transaction after exception produced other exception.");
                SafeDispose(connection, "Disposing the connection after exception produced other exception");
            }

            return(new DueTimeoutsResult(dueTimeouts, () => CommitAndClose(connection, transaction)));
        }