Beispiel #1
0
        /// <summary>
        /// 监听redis_cmd
        /// </summary>
        /// <param name="nodeId">nodeId</param>
        private static void ListenCmd(int nodeId)
        {
            _redisProvider.DB = 0;
            var jobIds = _redisProvider.Keys("*");

            if (!jobIds?.Any() ?? false)
            {
                return;
            }
            jobIds.ForEach(jobId =>
            {
                if ((TbJob.Find("ID", jobId)?.NodeID ?? 0) != nodeId)
                {
                    return;
                }
                var cmd = _redisProvider.Get <string>(jobId, DataType.String).ToJsonEntity <TbCommand>();
                if (cmd == null)
                {
                    return;
                }
                JobHelper.Excute(cmd);
                cmd.Time = DateTime.Now.TimeSpan();
                if (cmd.Success != 1)
                {
                    return;
                }
                cmd.SaveAsync();
                _redisProvider.Delete(jobId);
            });
        }