public void CanPutItemsOnAQueue()
        {
            Dictionary <string, string> person = new Dictionary <string, string>();

            person.Add("name", "chris");
            Assert.That(Resque.Push("people", person), Is.True);
        }
Example #2
0
        internal static Worker[] all()
        {
            var workers = from id in Resque.redis().GetMembersOfSet("resque:workers")
                          select find(Encoding.UTF8.GetString(id));

            return(workers.ToArray <Worker>());
        }
 public void KnowsWhoIsWorking()
 {
     worker.work(0,
                 (Job job) => {
         Assert.That(Resque.working()[0].workerId(), Is.EqualTo(worker.workerId())); return(true);
     });
 }
 public void CanPullItemsOffAQueue()
 {
     Assert.That("chris", Is.EqualTo(((Dictionary <string, object>)Resque.Pop("people"))["name"]));
     Assert.That("bob", Is.EqualTo(((Dictionary <string, object>)Resque.Pop("people"))["name"]));
     Assert.That("mark", Is.EqualTo(((Dictionary <string, object>)Resque.Pop("people"))["name"]));
     Assert.That(Resque.Pop("people"), Is.Null);
 }
 public void InsertsItselfIntoTheWorkersListOnStartup()
 {
     worker.work(0,
                 (Job job) =>
     {
         Assert.That(Resque.workers()[0].workerId(), Is.EqualTo(worker.workerId())); return(true);
     });
 }
        public void CanReQueueJobs()
        {
            Job.create("jobs", "resque.DummyJob", 20, "/tmp");
            Job job = Resque.Reserve("jobs");

            job.recreate();
            Assert.That(job, Is.EqualTo(Resque.Reserve("jobs")));
        }
Example #7
0
 private void setStarted()
 {
     currentTimeFormatted();
     Resque.redis().Set(new Dictionary <string, byte[]>()
     {
         { startedKey(), Encoding.UTF8.GetBytes(currentTimeFormatted()) }
     });
 }
Example #8
0
        public void Init()
        {
            // This is the IP address of my computer running Redis.
            server = "ec2-184-73-7-218.compute-1.amazonaws.com";
            //server = "192.168.56.102";

            Resque.setRedis(new Redis(server, 6379));
            Resque.redis().FlushAll();
        }
 public void RemovesItselfFromTheWorkersListOnShutdown()
 {
     worker.work(0,
                 (Job job) =>
     {
         Assert.That(Resque.workers()[0].workerId(), Is.EqualTo(worker.workerId())); return(true);
     });
     Assert.That(Resque.workers().Length, Is.EqualTo(0));
 }
Example #10
0
 public void KnowsHowBigAQueueIs()
 {
     Assert.That(Resque.size("people"), Is.EqualTo(3));
     Assert.That("chris", Is.EqualTo(((Dictionary <string, object>)Resque.Pop("people"))["name"]));
     Assert.That(Resque.size("people"), Is.EqualTo(2));
     Resque.Pop("people");
     Resque.Pop("people");
     Assert.That(Resque.size("people"), Is.EqualTo(0));
 }
Example #11
0
        private void setWorkingOn(Job job)
        {
            job.worker = this;
            string data = Resque.encode(new Dictionary <string, object>()
            {
                { "queue", job.queue }, { "run_at", currentTimeFormatted() }, { "payload", job.payload }
            });

            Resque.redis().Set("resque:worker:" + workerId(), data);
        }
Example #12
0
        public void Init()
        {
            server = "ec2-184-73-7-218.compute-1.amazonaws.com";
            //string server = "192.168.56.102";

            Resque.setRedis(new Redis(server, 6379));
            Resque.redis().FlushAll();
            worker = new Worker("jobs");
            //Job.create("jobs", "resque.DummyJob", 20, "/tmp");
        }
Example #13
0
        internal static Job Reserve(string queue)
        {
            Dictionary <string, object> payload = Resque.Pop(queue);

            if (payload == null)
            {
                return(null);
            }
            return(new Job(queue, payload));
        }
Example #14
0
        public void CanPutJobsOnTheQueueByAskingWhichQueueTheyAreInterestedIn()
        {
            Assert.That(0, Is.EqualTo(Resque.size("tester")));
            Assert.IsTrue(Resque.enqueue("resque.DummyJob", 20, "/tmp"));
            Assert.IsTrue(Resque.enqueue("resque.DummyJob", 20, "/tmp"));

            Job job = Resque.Reserve("tester");

            Assert.That(20, Is.EqualTo(job.args()[0]));
            Assert.That("/tmp", Is.EqualTo(job.args()[1]));
        }
Example #15
0
        public Type PayloadClass()
        {
            string className = (string)payload["class"];

            if (Resque.getAssemblyQualifier() != null)
            {
                className += Resque.getAssemblyQualifier();
            }

            return(Type.GetType(className, true));
        }
Example #16
0
 public void RemovesWorkerWithStringifiedId()
 {
     worker.work(0,
                 (Job job) =>
     {
         var workerId = Resque.workers()[0].workerId();
         Resque.removeWorker(workerId);
         Assert.That(Resque.workers().Length, Is.EqualTo(0));
         return(true);
     });
 }
Example #17
0
 public static bool create(string queue, string className, params object[] args)
 {
     if (String.IsNullOrEmpty(className))
     {
         throw new NoClassError();
     }
     Resque.Push(queue, new Dictionary <String, Object>()
     {
         { "class", className }, { "args", args }
     });
     return(true);
 }
Example #18
0
        public void CanGrabJobsOffAQueue()
        {
            //Job.create("jobs", "dummy-job", 20, "/tmp"); FIXME NEED TO DEAL WITH THIS
            Job.create("jobs", "resque.DummyJob", 20, "/tmp");
            Job job = Resque.Reserve("jobs");

            Assert.AreEqual("resque.DummyJob", job.PayloadClass().FullName);
            var num = job.args()[0];

            Assert.AreEqual(20, num);
            Assert.That("/tmp", Is.EqualTo(job.args()[1]));
        }
Example #19
0
 public void KnowsWhatQuestsItIsManaging()
 {
     Assert.That(Resque.queues(), Is.EqualTo(new string[1] {
         "people"
     }));
     Resque.Push("cars", new Dictionary <string, string>()
     {
         { "make", "bmw" }
     });
     Assert.That(Resque.queues(), Is.EqualTo(new string[2] {
         "cars", "people"
     }));
 }
Example #20
0
        public void CanWorkOnMultipleQueues()
        {
            Job.create("high", "resque.GoodJob");
            Job.create("critical", "resque.GoodJob");

            worker = new Worker(new string[] { "critical", "high" });

            worker.process();
            Assert.AreEqual(Resque.size("high"), 1);
            Assert.AreEqual(Resque.size("critical"), 0);

            worker.process();
            Assert.AreEqual(Resque.size("high"), 0);
        }
Example #21
0
 public void CanDeleteAQueue()
 {
     Resque.Push("cars", new Dictionary <string, string>()
     {
         { "make", "bmw" }
     });
     Assert.That(Resque.queues(), Is.EqualTo(new string[2] {
         "cars", "people"
     }));
     Resque.RemoveQueue("people");
     Assert.That(Resque.queues(), Is.EqualTo(new string[1] {
         "cars"
     }));
 }
Example #22
0
        public void CanTestForEquality()
        {
            Assert.IsTrue(Job.create("jobs", "resque.DummyJob", 20, "/tmp"));
            Assert.IsTrue(Job.create("jobs", "resque.DummyJob", 20, "/tmp"));
            //Assert.IsTrue(Job.create("jobs", "dummy-job", 20, "/tmp"));  NEED TO  MAKE THIS WORK
            Assert.That(Resque.Reserve("jobs"), Is.EqualTo(Resque.Reserve("jobs")));

            Assert.IsTrue(Job.create("jobs", "resque.NotDummyJob", 20, "/tmp"));
            Assert.IsTrue(Job.create("jobs", "resque.DummyJob", 20, "/tmp"));
            Assert.That(Resque.Reserve("jobs"), Is.Not.EqualTo(Resque.Reserve("jobs")));

            Assert.IsTrue(Job.create("jobs", "resque.DummyJob", 20, "/tmp"));
            Assert.IsTrue(Job.create("jobs", "resque.DummyJob", 30, "/tmp"));
            Assert.That(Resque.Reserve("jobs"), Is.Not.EqualTo(Resque.Reserve("jobs")));
        }
Example #23
0
        public Worker(string queue)
        {
            string[] queues = null;

            if (queue == "*")
            {
                queues = Resque.queues();
            }
            else
            {
                queues = new string[] { queue };
            }

            this.queues = queues;
        }
Example #24
0
        public void Init()
        {
            // This is the IP address of my computer running Redis.
            server = "ec2-184-73-7-218.compute-1.amazonaws.com";
            //server = "192.168.56.102";

            Resque.setRedis(new Redis(server, 6379));
            Resque.redis().FlushAll();

            Exception ex     = new Exception(testString);
            Worker    worker = new Worker();
            String    queue  = testString;

            payload = Encoding.UTF8.GetBytes(testString);

            myRedis = new Failure.Redis(ex, worker, queue, payload);
        }
Example #25
0
        public void CanWorkOnAllQueues()
        {
            Job.create("high", "resque.GoodJob");
            Job.create("critical", "resque.GoodJob");
            Job.create("blahblah", "resque.GoodJob");

            worker = new Worker("*");

            worker.work(0);

            Console.WriteLine(Resque.size("high"));
            Console.WriteLine(Resque.size("critical"));
            Console.WriteLine(Resque.size("blahblah"));

            Assert.AreEqual(Resque.size("high"), 0);
            Assert.AreEqual(Resque.size("critical"), 0);
            Assert.AreEqual(Resque.size("blahblah"), 0);
        }
Example #26
0
        public void CanPeekAtMultipleItemsOnQueue()
        {
            ArrayList result = Resque.Peek("people", 1, 1);

            Assert.That("bob", Is.EqualTo((((Dictionary <string, object>)result[0]))["name"]));

            result = Resque.Peek("people", 1, 2);
            Assert.That(((Dictionary <string, object>)result[0])["name"], Is.EqualTo("bob"));
            Assert.That(((Dictionary <string, object>)result[1])["name"], Is.EqualTo("mark"));

            result = Resque.Peek("people", 0, 2);
            Assert.That(((Dictionary <string, object>)result[0])["name"], Is.EqualTo("chris"));
            Assert.That(((Dictionary <string, object>)result[1])["name"], Is.EqualTo("bob"));

            result = Resque.Peek("people", 2, 1);
            Assert.That(((Dictionary <string, object>)result[0])["name"], Is.EqualTo("mark"));
            Assert.That(Resque.Peek("people", 3), Is.Null);
        }
Example #27
0
        public void Init()
        {
            String server = "ec2-184-73-7-218.compute-1.amazonaws.com";

            //String server = "192.168.56.102";
            new Redis(server, 6379).FlushAll(); // This is the IP address of my computer running Redis.
            Resque.setRedis(new Redis(server, 6379));
            Resque.Push("people", new Dictionary <string, string>()
            {
                { "name", "chris" }
            });
            Resque.Push("people", new Dictionary <string, string>()
            {
                { "name", "bob" }
            });
            Resque.Push("people", new Dictionary <string, string>()
            {
                { "name", "mark" }
            });
        }
Example #28
0
        internal static Worker[] working()
        {
            Worker[] workers = all();
            if (workers.Length == 0)
            {
                return(workers);
            }
            string[] names = (from worker in workers
                              select "resque:worker:" + worker.workerId()).ToArray <string>();
            string[] redisValues = (from bytes in Resque.redis().GetKeys(names)
                                    select bytes == null ? null : Encoding.UTF8.GetString(bytes)).ToArray <string>();;
            List <Worker> results = new List <Worker>();

            for (int i = 0; i < names.Length; i++)
            {
                if (!String.IsNullOrEmpty(redisValues[i]))
                {
                    results.Add(find(Regex.Replace(names[i], "resque:worker:", "")));
                }
            }
            return(results.ToArray());
        }
Example #29
0
 public void CanAskResqueForQueueSize()
 {
     Assert.That(0, Is.EqualTo(Resque.size("a_queue")));
     Job.create("a_queue", "resque.DummyJob", 1, "asdf");
     Assert.That(1, Is.EqualTo(Resque.size("a_queue")));
 }
Example #30
0
 internal void EnqueueUninferrableJob()
 {
     Resque.enqueue("resque.UninferrableInvalidJob", 123);
 }