public void CanPutItemsOnAQueue() { Dictionary <string, string> person = new Dictionary <string, string>(); person.Add("name", "chris"); Assert.That(Resque.Push("people", person), Is.True); }
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"))); }
private void setStarted() { currentTimeFormatted(); Resque.redis().Set(new Dictionary <string, byte[]>() { { startedKey(), Encoding.UTF8.GetBytes(currentTimeFormatted()) } }); }
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)); }
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)); }
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); }
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"); }
internal static Job Reserve(string queue) { Dictionary <string, object> payload = Resque.Pop(queue); if (payload == null) { return(null); } return(new Job(queue, payload)); }
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])); }
public Type PayloadClass() { string className = (string)payload["class"]; if (Resque.getAssemblyQualifier() != null) { className += Resque.getAssemblyQualifier(); } return(Type.GetType(className, true)); }
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); }); }
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); }
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])); }
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" })); }
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); }
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" })); }
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"))); }
public Worker(string queue) { string[] queues = null; if (queue == "*") { queues = Resque.queues(); } else { queues = new string[] { queue }; } this.queues = queues; }
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); }
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); }
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); }
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" } }); }
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()); }
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"))); }
internal void EnqueueUninferrableJob() { Resque.enqueue("resque.UninferrableInvalidJob", 123); }