public void Redis_QueueTest()
        {
            RedisScheduler redisScheduler = new RedisScheduler("localhost", "");

            ISpider spider   = new TestSpider();
            Request request1 = new Request("http://www.ibm.com/1", 1, null);
            Request request2 = new Request("http://www.ibm.com/2", 1, null);
            Request request3 = new Request("http://www.ibm.com/3", 1, null);
            Request request4 = new Request("http://www.ibm.com/4", 1, null);

            redisScheduler.Push(request1, spider);
            redisScheduler.Push(request2, spider);
            redisScheduler.Push(request3, spider);
            redisScheduler.Push(request4, spider);

            Request result = redisScheduler.Poll(spider);

            Assert.AreEqual("http://www.ibm.com/4", result.Url.ToString());
            Request result1 = redisScheduler.Poll(spider);

            Assert.AreEqual("http://www.ibm.com/3", result1.Url.ToString());
            redisScheduler.Dispose();

            RedisSchedulerManager m = new RedisSchedulerManager("localhost");

            m.RemoveTask(spider.Identity);
        }
Beispiel #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string host = ConfigurationManager.AppSettings["redishost"];
            string pass = ConfigurationManager.AppSettings["redishostpass"];

            if (!string.IsNullOrEmpty(host))
            {
                manager = new RedisSchedulerManager(host, pass);
            }

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if ((!IsDisposed || IsHandleCreated || this.components != null))
                    {
                        Invoke(new Action(RefreshTask));
                    }
                    Thread.Sleep(60000);
                }
            });

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    if ((!IsDisposed || IsHandleCreated || this.components != null))
                    {
                        Invoke(new Action(() =>
                        {
                            if (!string.IsNullOrEmpty(_selectedIdentify))
                            {
                                SpiderStatus spiderStatus = manager.GetTaskStatus(_selectedIdentify);

                                this.tbErrorPageCount.Text      = spiderStatus.ErrorPageCount.ToString();
                                this.tbLeftRequestCount.Text    = spiderStatus.LeftPageCount.ToString();
                                this.tbTotalRequestCount.Text   = spiderStatus.TotalPageCount.ToString();
                                this.tbPagePerSecond.Text       = spiderStatus.PagePerSecond.ToString(CultureInfo.InvariantCulture);
                                this.tbRunningProcessCount.Text = spiderStatus.AliveThreadCount.ToString();
                                this.tbProcessCount.Text        = spiderStatus.ThreadCount.ToString();
                                this.tbStartTime.Text           = spiderStatus.StartTime.ToString(CultureInfo.InvariantCulture);
                                this.tbEndTime.Text             = spiderStatus.EndTime.ToString(CultureInfo.InvariantCulture);
                                this.tbTaskStatus.Text          = spiderStatus.Status;
                            }
                            else
                            {
                                SentEmptyInfo();
                            }
                        }));
                    }
                    Thread.Sleep(1000);
                }
            });
        }
        public void RedisTest()
        {
            RedisScheduler redisScheduler = new RedisScheduler("localhost", "");

            ISpider spider  = new TestSpider();
            Request request = new Request("http://www.ibm.com/developerworks/cn/java/j-javadev2-22/", 1, null);

            request.PutExtra("1", "2");
            redisScheduler.Push(request, spider);
            Request result = redisScheduler.Poll(spider);

            Assert.AreEqual("http://www.ibm.com/developerworks/cn/java/j-javadev2-22/", result.Url.ToString());
            Request result1 = redisScheduler.Poll(spider);

            Assert.IsNull(result1);
            redisScheduler.Dispose();

            RedisSchedulerManager m = new RedisSchedulerManager("localhost");

            m.RemoveTask(spider.Identity);
        }