コード例 #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
        void MarkAsProcessed(DueAdoNetTimeout dueTimeout)
        {
            using (var connection = factory.OpenConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = string.Format(@"DELETE FROM ""{0}"" WHERE ""id"" = @id", timeoutsTableName);
                    command.AddParameter("id", dueTimeout.Id);

                    command.ExecuteNonQuery();
                }
        }
コード例 #3
0
            public static DueAdoNetTimeout Create(Action <DueAdoNetTimeout> markAsProcessedAction, string timeoutsTableName, IDataReader reader)
            {
                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 timeout = new DueAdoNetTimeout(markAsProcessedAction, timeoutsTableName, id, replyTo, correlationId, timeToReturn, sagaId, customData);

                return(timeout);
            }
コード例 #4
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)));
        }
コード例 #5
0
			public static DueAdoNetTimeout Create(Action<DueAdoNetTimeout> markAsProcessedAction, string timeoutsTableName, IDataReader reader)
			{
				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 timeout = new DueAdoNetTimeout(markAsProcessedAction, timeoutsTableName, id, replyTo, correlationId, timeToReturn, sagaId, customData);

				return timeout;
			}
コード例 #6
0
		void MarkAsProcessed(DueAdoNetTimeout dueTimeout)
		{
			using (var connection = factory.OpenConnection())
			using (var command = connection.CreateCommand())
			{
				command.CommandText = string.Format(@"DELETE FROM ""{0}"" WHERE ""id"" = @id", timeoutsTableName);
				command.AddParameter("id", dueTimeout.Id);

				command.ExecuteNonQuery();
			}
		}