Ejemplo n.º 1
0
        public async Task RetryTest()
        {
            var service = new Service(new MockRedisDatabase());

            DivvyUp.RegisterJobsFromAssembly(typeof(TestJob));
            var       worker          = new Worker(service, "test");
            Exception workerException = null;

            worker.OnError                += (exc) => workerException = exc;
            worker.CheckinInterval         = 1;
            worker.DelayAfterInternalError = 0;
            var job = new TestJob("fail");

            job.Retries = 1;
            await service.Enqueue(job);

            await worker.Work(false);

            Assert.NotNull(workerException);
            workerException = null;
            await worker.Work(false);

            Assert.NotNull(workerException);

            await worker.Work(false);
        }
Ejemplo n.º 2
0
        public async Task WorkerPool()
        {
            DivvyUp.RegisterJobsFromAssembly(typeof(TestJob));
            var service = new Service(new MockRedisDatabase());
            var pool    = new WorkerPool(service);

            pool.AddWorker("test");
            pool.AddWorkers(3, "test");
            foreach (var worker in pool.Workers)
            {
                worker.CheckinInterval         = 1;
                worker.DelayAfterInternalError = 0;
                worker.NoWorkCheckInterval     = 0;
            }
            pool.WorkInBackground();
            for (int i = 0; i < 40; i++)
            {
                await service.Enqueue(new TestJob("delay"));
            }

            var start = DateTime.UtcNow;

            while (DateTime.UtcNow - start < TimeSpan.FromSeconds(3.5))
            {
                ;
            }

            await pool.Stop();

            Assert.Equal(40, TestJob.Count("delay"));
        }
Ejemplo n.º 3
0
        public async Task ReclaimStuckWork()
        {
            var redis = new MockRedisDatabase();
            await redis.HashSetAsync($"divvyup::workers", "badworkerbad", DateTimeOffset.UtcNow.ToUnixTimeSeconds() - 60 * 60);

            await redis.HashSetAsync($"divvyup::worker::badworkerbad::job", "started_at", DateTimeOffset.UtcNow.ToUnixTimeSeconds() - 60 * 60);

            await redis.HashSetAsync($"divvyup::worker::badworkerbad::job", "work", JsonConvert.SerializeObject(new
            {
                @class = typeof(TestJob).FullName,
                queue  = "test",
                args   = new object[0]
            }));

            DivvyUp.RegisterJobsFromAssembly(typeof(TestJob));
            var service = new Service(redis);
            var worker  = new Worker(service, "test");

            worker.CheckinInterval         = 1;
            worker.DelayAfterInternalError = 0;
            await worker.Work(false);

            Assert.Equal(1, TestJob.Count("default"));
        }