Exemplo n.º 1
0
    def test_cron_make_up(self):
        task = make_task()
        queue = make_queue()
        now = datetime.utcnow()
        s = CronSchedule(encoding='o*d*w*h*m*s%s' % ((now.second - 1) % 60),
                         task=task,
                         queue=queue,
                         repetitions=0,
                         remaining=0,
                         make_up=False)
        s.base = now - timedelta(seconds=2)
        s.save()
        self._scheduler.flag.set()
        wait_until(lambda: s.instances.count() == 1, 3)

        now = datetime.utcnow()
        s = CronSchedule(encoding='o*d*w*h*m*s*',
                         task=task,
                         queue=queue,
                         repetitions=0,
                         remaining=0,
                         make_up=True)
        s.base = now - timedelta(seconds=5)
        s.save()
        self._scheduler.flag.set()
        wait_until(lambda: s.instances.count() == 6, 1)
Exemplo n.º 2
0
 def test_bad_schedule(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, "o*d*w*h*m*s*")
     s.encoding = "gibberish"
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: CronSchedule.objects.get(pk=s.pk).deleted, 2)
Exemplo n.º 3
0
 def test_bad_schedule(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, "o*d*w*h*m*s*")
     s.encoding = "gibberish"
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: CronSchedule.objects.get(pk=s.pk).deleted, 2)
Exemplo n.º 4
0
 def test_make_up(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 1, 10, -10, True)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 10, 5)
     s = Schedule.create(task, queue, 60, 10, -10, False)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 5)
Exemplo n.º 5
0
 def test_make_up(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 1, 10, -10, True)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 10, 5)
     s = Schedule.create(task, queue, 60, 10, -10, False)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 5)
Exemplo n.º 6
0
 def test_update_schedule(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, 'o*d*w*h*m*s*', 10)
     self._scheduler.flag.set()
     wait_until(lambda: queue.count() == 2, 5)
     s.encoding = 'o*d*w*h*m*s4'
     s.save()
     self.assertRaises(Exception,
         lambda: wait_until(lambda: s.instances.count() > 3, 3))
Exemplo n.º 7
0
 def test_update_schedule(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, 'o*d*w*h*m*s*', 10)
     self._scheduler.flag.set()
     wait_until(lambda: queue.count() == 2, 5)
     s.encoding = 'o*d*w*h*m*s4'
     s.save()
     self.assertRaises(
         Exception, lambda: wait_until(lambda: s.instances.count() > 3, 3))
Exemplo n.º 8
0
 def test_duplicate(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 1, 2, start=2)
     self._scheduler.flag.set()
     wait_until(lambda: self.scheduler.schedules.count() == 1, 2)
     s = Schedule.objects.get(pk=s.pk)
     s.scheduler = None
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 2, 5)
Exemplo n.º 9
0
 def test_duplicate(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 1, 2, start=2)
     self._scheduler.flag.set()
     wait_until(lambda: self.scheduler.schedules.count() == 1, 2)
     s = Schedule.objects.get(pk=s.pk)
     s.scheduler = None
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 2, 5)
Exemplo n.º 10
0
 def test_cron(self):
     task = make_task()
     queue = make_queue()
     s = CronSchedule.create(task, queue, 'o*d*w*h*m*s*', 3)
     self._scheduler.flag.set()
     wait_until(lambda: queue.count() == 3, 8)
     enqueued = map(lambda i: i.enqueued, s.instances)
     def fold(acc, e):
         self.assertEqual(e - acc, timedelta(seconds=1))
         return e
     reduce(fold, enqueued)
Exemplo n.º 11
0
 def test_reload(self):
     task = make_task()
     queue = make_queue()
     now = datetime.utcnow()
     s = CronSchedule.create(task, queue,
                             'o*d*w*h*m*s%s' % ((now.second - 1) % 60), 1)
     self._scheduler.flag.set()
     wait_until(lambda: self.scheduler.cronschedules.count() == 1, 5)
     CronSchedule.objects.get(pk=s.pk).reschedule('o*d*w*h*m*s*')
     self.scheduler.make_request(Request.RELOAD)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 10)
Exemplo n.º 12
0
 def test_reload(self):
     task = make_task()
     queue = make_queue()
     now = datetime.utcnow()
     s = CronSchedule.create(task, queue, 'o*d*w*h*m*s%s' %
         ((now.second - 1) % 60), 1)
     self._scheduler.flag.set()
     wait_until(lambda: self.scheduler.cronschedules.count() == 1, 5)
     CronSchedule.objects.get(pk=s.pk).reschedule('o*d*w*h*m*s*')
     self.scheduler.make_request(Request.RELOAD)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 10)
Exemplo n.º 13
0
    def test_cron(self):
        task = make_task()
        queue = make_queue()
        s = CronSchedule.create(task, queue, 'o*d*w*h*m*s*', 3)
        self._scheduler.flag.set()
        wait_until(lambda: queue.count() == 3, 8)
        enqueued = map(lambda i: i.enqueued, s.instances)

        def fold(acc, e):
            self.assertEqual(e - acc, timedelta(seconds=1))
            return e

        reduce(fold, enqueued)
Exemplo n.º 14
0
 def setUp(self):
     self.queue = testing.make_queue()
     self.tasks = [testing.make_task('JobTask%s' % i) for i in range(6)]
     self.job = Job.objects.create(name='TestJob')
     self.nodes = [JobNode.objects.create(task=self.tasks[i], job=self.job)
         for i in range(6)]
     n = self.nodes
     Dependency.objects.create(parent=n[0], child=n[2])
     Dependency.objects.create(parent=n[0], child=n[3])
     Dependency.objects.create(parent=n[1], child=n[4])
     Dependency.objects.create(parent=n[2], child=n[3])
     Dependency.objects.create(parent=n[2], child=n[5])
     Dependency.objects.create(parent=n[3], child=n[5])
     Dependency.objects.create(parent=n[4], child=n[5])
Exemplo n.º 15
0
 def setUp(self):
     self.queue = testing.make_queue()
     self.tasks = [testing.make_task('JobTask%s' % i) for i in range(6)]
     self.job = Job.objects.create(name='TestJob')
     self.nodes = [
         JobNode.objects.create(task=self.tasks[i], job=self.job)
         for i in range(6)
     ]
     n = self.nodes
     Dependency.objects.create(parent=n[0], child=n[2])
     Dependency.objects.create(parent=n[0], child=n[3])
     Dependency.objects.create(parent=n[1], child=n[4])
     Dependency.objects.create(parent=n[2], child=n[3])
     Dependency.objects.create(parent=n[2], child=n[5])
     Dependency.objects.create(parent=n[3], child=n[5])
     Dependency.objects.create(parent=n[4], child=n[5])
Exemplo n.º 16
0
 def test_cron_make_up(self):
     task = make_task()
     queue = make_queue()
     now = datetime.utcnow()
     s = CronSchedule(encoding='o*d*w*h*m*s%s' % ((now.second - 1) % 60),
         task=task, queue=queue, repetitions=0, remaining=0, make_up=False)
     s.base = now - timedelta(seconds=2)
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 1, 3)
     
     now = datetime.utcnow()
     s = CronSchedule(encoding='o*d*w*h*m*s*',
         task=task, queue=queue, repetitions=0, remaining=0, make_up=True)
     s.base = now - timedelta(seconds=5)
     s.save()
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 6, 1)
Exemplo n.º 17
0
 def test_schedule(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 0, 5)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 5, 5)
Exemplo n.º 18
0
 def test_schedule(self):
     task = make_task()
     queue = make_queue()
     s = Schedule.create(task, queue, 0, 5)
     self._scheduler.flag.set()
     wait_until(lambda: s.instances.count() == 5, 5)