コード例 #1
0
 /// <summary>
 /// Handles the specified command.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns></returns>
 public DateTime?Handle(SendHeartBeatCommand <long> command)
 {
     using (var conn = new SqlConnection(_connectionInformation.ConnectionString))
     {
         conn.Open();
         using (var commandSql = conn.CreateCommand())
         {
             commandSql.CommandText = _commandCache.GetCommand(CommandStringTypes.SendHeartBeat);
             commandSql.Parameters.Add("@QueueID", SqlDbType.BigInt);
             commandSql.Parameters["@QueueID"].Value = command.QueueId;
             commandSql.Parameters.Add("@status", SqlDbType.Int);
             commandSql.Parameters["@status"].Value = Convert.ToInt16(QueueStatuses.Processing);
             using (var reader = commandSql.ExecuteReader())
             {
                 if (reader.RecordsAffected != 1)
                 {
                     return(null);                             //return null if the record was not updated.
                 }
                 if (reader.Read())
                 {
                     return(reader.GetDateTime(0));
                 }
             }
             return(null); //return null if the record was not updated.
         }
     }
 }
コード例 #2
0
        /// <inheritdoc />
        public DateTime?Handle(SendHeartBeatCommand <int> command)
        {
            using (var db = _connectionInformation.GetDatabase())
            {
                db.Database.BeginTrans();
                try
                {
                    var col = db.Database.GetCollection <Schema.MetaDataTable>(_tableNameHelper.MetaDataName);

                    var results = col.Query()
                                  .Where(x => x.QueueId == command.QueueId)
                                  .Limit(1)
                                  .ToList();

                    DateTime?date = null;
                    if (results.Count == 1)
                    {
                        var record = results[0];
                        date             = DateTime.UtcNow;
                        record.HeartBeat = date;
                        col.Update(record);
                    }

                    db.Database.Commit();
                    return(date);
                }
                catch
                {
                    db.Database.Rollback();
                    throw;
                }
            }
        }
コード例 #3
0
        /// <inheritdoc />
        public IHeartBeatStatus Send(IMessageContext context)
        {
            var command = new SendHeartBeatCommand((long)context.MessageId.Id.Value);
            var oDate   = _commandHandler.Handle(command);

            return(new HeartBeatStatus(new MessageQueueId(command.QueueId), oDate));
        }
コード例 #4
0
        public void Create_Default()
        {
            const int id   = 19334;
            var       test = new SendHeartBeatCommand <long>(id);

            Assert.Equal(id, test.QueueId);
        }
コード例 #5
0
        public void Create_Default(string number)
        {
            var id   = new RedisQueueId(number);
            var test = new SendHeartBeatCommand(id);

            Assert.Equal(id, test.QueueId);
        }
        /// <inheritdoc />
        public DateTime Handle(SendHeartBeatCommand <long> command, IDbCommand dbCommand, CommandStringTypes commandType)
        {
            dbCommand.CommandText = _commandCache.GetCommand(commandType);

            var param = dbCommand.CreateParameter();

            param.ParameterName = "@QueueID";
            param.Value         = command.QueueId;
            param.DbType        = DbType.Int64;
            dbCommand.Parameters.Add(param);

            param = dbCommand.CreateParameter();
            param.ParameterName = "@Status";
            param.DbType        = DbType.Int32;
            param.Value         = Convert.ToInt16(QueueStatuses.Processing);
            dbCommand.Parameters.Add(param);

            param = dbCommand.CreateParameter();
            param.ParameterName = "@date";
            param.DbType        = DbType.Int64;
            var date = _getTime.GetCurrentUtcDate();

            param.Value = date.Ticks;
            dbCommand.Parameters.Add(param);

            return(date);
        }
コード例 #7
0
 /// <inheritdoc />
 public DateTime?Handle(SendHeartBeatCommand <long> command)
 {
     using (var conn = _connectionFactory.Create())
     {
         conn.Open();
         using (var commandSql = conn.CreateCommand())
         {
             var date    = _prepareCommand.Handle(command, commandSql, CommandStringTypes.SendHeartBeat);
             var records = commandSql.ExecuteNonQuery();
             if (records != 1)
             {
                 return(null);
             }
             return(date);
         }
     }
 }
コード例 #8
0
        /// <inheritdoc />
        public long Handle(SendHeartBeatCommand <string> command)
        {
            if (_connection.IsDisposed)
            {
                return(0);
            }

            if (string.IsNullOrWhiteSpace(command.QueueId))
            {
                return(0);
            }

            var db   = _connection.Connection.GetDatabase();
            var date = _unixTimeFactory.Create().GetCurrentUnixTimestampMilliseconds();

            db.SortedSetAdd(_redisNames.Working, command.QueueId, date, When.Exists);

            return(date);
        }
コード例 #9
0
        public void Create_Default(string number)
        {
            var test = new SendHeartBeatCommand <string>(number);

            Assert.Equal(number, test.QueueId);
        }