Exemple #1
0
    def test_health_for_queue_completion_estimates(self, mock_now):
        mock_now.return_value = timezone.now()
        job = TestRemoveOldJobs.create_job(1)
        queue_health = api.health(stats.estimate_queue_completion).get(
            'queue', None)
        self.assertEquals(queue_health['estimated-completion-current-job'], 0)
        self.assertEquals(queue_health['estimated-completion'], 0)

        job_started = mock_now.return_value - datetime.timedelta(seconds=9)
        job.started = job_started
        job.executed = job_started + datetime.timedelta(seconds=5)
        job.save()

        queue_health = api.health(stats.estimate_queue_completion).get(
            'queue', None)
        self.assertEquals(queue_health['estimated-completion-current-job'], 0)
        self.assertEquals(queue_health['estimated-completion'], 0)

        job2 = TestRemoveOldJobs.create_job(1)
        job2.started = mock_now.return_value - datetime.timedelta(seconds=3)
        job2.save()

        #queue_health = api.health().get('queue', None)
        queue_health = api.health(stats.estimate_queue_completion).get(
            'queue', None)
        self.assertAlmostEqual(
            queue_health['estimated-completion-current-job'], 2.0)
        self.assertAlmostEqual(queue_health['estimated-completion'], 2.0)
 def test_health(self):
     """Excecute command.
     """
     print(health())
     print(management.call_command('queue_health'))
     with patch('async.management.commands.queue_health.dumps',
                lambda x: self.assertEqual(x, health())):
         management.call_command('queue_health')
Exemple #3
0
 def test_health(self):
     """Excecute command.
     """
     print( health())
     print( management.call_command('queue_health'))
     with patch(
             'async.management.commands.queue_health.dumps',
             lambda x: self.assertEqual(x, health())):
         management.call_command('queue_health')
Exemple #4
0
    def test_health_for_executed_jobs(self):
        job1 = TestRemoveOldJobs.create_job(1)
        job_started = timezone.now()
        job1.started = job_started
        job1.executed = job_started + datetime.timedelta(seconds=5)
        job1.save()

        job2 = TestRemoveOldJobs.create_job(2)
        job2.started = job_started
        job2.executed = job_started + datetime.timedelta(seconds=10)
        job2.save()

        job2_a = TestRemoveOldJobs.create_job(2)
        job2_a.started = job_started
        job2_a.save()

        TestRemoveOldJobs.create_job(1)

        queue_health = api.health().get('queue', None)

        self.assertEquals(queue_health['not-executed'], 2)
        self.assertEquals(queue_health['executed'], 2)
        self.assertEquals(queue_health['oldest-executed'],
            '/slumber/async/Job/data/%s/' % job1.pk)
        self.assertEquals(queue_health['most-recent-executed'],
            '/slumber/async/Job/data/%s/' % job2.pk)
Exemple #5
0
    def test_health_for_executed_jobs(self):
        job1 = TestRemoveOldJobs.create_job(1)
        job_started = timezone.now()
        job1.started = job_started
        job1.executed = job_started + datetime.timedelta(seconds=5)
        job1.save()

        job2 = TestRemoveOldJobs.create_job(2)
        job2.started = job_started
        job2.executed = job_started + datetime.timedelta(seconds=10)
        job2.save()

        job2_a = TestRemoveOldJobs.create_job(2)
        job2_a.started = job_started
        job2_a.save()

        TestRemoveOldJobs.create_job(1)

        queue_health = api.health().get('queue', None)

        self.assertEquals(queue_health['not-executed'], 2)
        self.assertEquals(queue_health['executed'], 2)
        self.assertEquals(queue_health['oldest-executed'],
                          '/slumber/async/Job/data/%s/' % job1.pk)
        self.assertEquals(queue_health['most-recent-executed'],
                          '/slumber/async/Job/data/%s/' % job2.pk)
Exemple #6
0
    def test_health_for_not_executed_jobs(self):
        TestRemoveOldJobs.create_job(1)
        TestRemoveOldJobs.create_job(2)

        queue_health = api.health().get('queue', None)

        self.assertEquals(queue_health['not-executed'], 2)
        self.assertEquals(queue_health['executed'], 0)
        self.assertEquals(queue_health['cancelled'], 0)
Exemple #7
0
 def test_health_with_options(self):
     """Excecute command.
     """
     with patch(
             'async.management.commands.queue_health.dumps',
             lambda x: self.assertEqual(x, health())):
         management.call_command('queue_health', algorithm='rough')
     self.assertRaises(BaseException, management.call_command,
                       'queue_health', algorithm='hello')
Exemple #8
0
    def test_health_for_not_executed_jobs(self):
        TestRemoveOldJobs.create_job(1)
        TestRemoveOldJobs.create_job(2)

        queue_health = api.health().get('queue', None)

        self.assertEquals(queue_health['not-executed'], 2)
        self.assertEquals(queue_health['executed'], 0)
        self.assertEquals(queue_health['cancelled'], 0)
 def test_health_with_options(self):
     """Excecute command.
     """
     with patch('async.management.commands.queue_health.dumps',
                lambda x: self.assertEqual(x, health())):
         management.call_command('queue_health', algorithm='rough')
     self.assertRaises(BaseException,
                       management.call_command,
                       'queue_health',
                       algorithm='hello')
Exemple #10
0
    def test_health_for_errors(self):
        dt_now = timezone.now()
        job1 = api.schedule('job-1', group=None)
        error1 = Error.objects.create(job=job1, executed=dt_now, exception="First", traceback="None")

        dt_now = dt_now + datetime.timedelta(seconds=10)
        error2 = Error.objects.create(job=job1, executed=dt_now, exception="Second", traceback="None")

        queue_errors = api.health().get('errors', None)

        self.assertEquals(queue_errors['number'], 2)
 def handle(self, *args, **options):
     """Command implementation.
     """
     algorithm = options.get('algorithm' or None)
     if algorithm == "rough":
         estimation_fn = estimate_rough_queue_completion
     elif algorithm == "precise" or algorithm is None:
         estimation_fn = estimate_queue_completion
     else:
         raise CommandError("Unknown option for estimation algorithm")
     print(dumps(health(estimation_fn)))
Exemple #12
0
 def handle(self, *args, **options):
     """Command implementation.
     """
     algorithm = options.get('algorithm' or None)
     if algorithm == "rough":
         estimation_fn = estimate_rough_queue_completion
     elif algorithm == "precise" or algorithm is None:
         estimation_fn = estimate_queue_completion
     else:
         raise CommandError("Unknown option for estimation algorithm")
     print(dumps(health(estimation_fn)))
Exemple #13
0
    def test_health_for_queue_completion_estimates(self, mock_now):
        mock_now.return_value = timezone.now()
        job = TestRemoveOldJobs.create_job(1)
        queue_health = api.health(stats.estimate_queue_completion).get('queue', None)
        self.assertEquals(queue_health['estimated-completion-current-job'], 0)
        self.assertEquals(queue_health['estimated-completion'], 0)

        job_started = mock_now.return_value - datetime.timedelta(seconds=9)
        job.started = job_started
        job.executed = job_started + datetime.timedelta(seconds=5)
        job.save()

        queue_health = api.health(stats.estimate_queue_completion).get('queue', None)
        self.assertEquals(queue_health['estimated-completion-current-job'], 0)
        self.assertEquals(queue_health['estimated-completion'], 0)

        job2 = TestRemoveOldJobs.create_job(1)
        job2.started = mock_now.return_value - datetime.timedelta(seconds=3)
        job2.save()

        #queue_health = api.health().get('queue', None)
        queue_health = api.health(stats.estimate_queue_completion).get('queue', None)
        self.assertAlmostEqual(queue_health['estimated-completion-current-job'], 2.0)
        self.assertAlmostEqual(queue_health['estimated-completion'], 2.0)
Exemple #14
0
    def test_health_for_errors(self):
        dt_now = timezone.now()
        job1 = api.schedule('job-1', group=None)
        error1 = Error.objects.create(job=job1,
                                      executed=dt_now,
                                      exception="First",
                                      traceback="None")

        dt_now = dt_now + datetime.timedelta(seconds=10)
        error2 = Error.objects.create(job=job1,
                                      executed=dt_now,
                                      exception="Second",
                                      traceback="None")

        queue_errors = api.health().get('errors', None)

        self.assertEquals(queue_errors['number'], 2)
Exemple #15
0
    def test_health_for_cancelled_jobs(self):
        dt_now = timezone.now()
        job1 = TestRemoveOldJobs.create_job(1)
        job1.cancelled = dt_now
        job1.save()

        job2 = TestRemoveOldJobs.create_job(2)
        job2.cancelled = dt_now + datetime.timedelta(seconds=10)
        job2.save()

        TestRemoveOldJobs.create_job(2)
        TestRemoveOldJobs.create_job(1)

        queue_health = api.health().get('queue', None)

        self.assertEquals(queue_health['cancelled'], 2)
        self.assertEquals(queue_health['oldest-cancelled'],
                          '/slumber/async/Job/data/%s/' % job1.pk)
        self.assertEquals(queue_health['most-recent-cancelled'],
                          '/slumber/async/Job/data/%s/' % job2.pk)
Exemple #16
0
    def test_health_for_cancelled_jobs(self):
        dt_now = timezone.now()
        job1 = TestRemoveOldJobs.create_job(1)
        job1.cancelled = dt_now
        job1.save()

        job2 = TestRemoveOldJobs.create_job(2)
        job2.cancelled = dt_now + datetime.timedelta(seconds=10)
        job2.save()

        TestRemoveOldJobs.create_job(2)
        TestRemoveOldJobs.create_job(1)

        queue_health = api.health().get('queue', None)

        self.assertEquals(queue_health['cancelled'], 2)
        self.assertEquals(queue_health['oldest-cancelled'],
            '/slumber/async/Job/data/%s/' % job1.pk)
        self.assertEquals(queue_health['most-recent-cancelled'],
            '/slumber/async/Job/data/%s/' % job2.pk)
Exemple #17
0
 def handle(self, **options):
     """Command implementation.
     """
     print dumps(health())
Exemple #18
0
 def get(self, _request, response, _app, _model):
     """Return the current queue health.
     """
     response['health'] = health()
Exemple #19
0
 def test_health(self):
     """Excecute command.
     """
     with patch("async.management.commands.queue_health.dumps", lambda x: self.assertEqual(x, health())):
         management.call_command("queue_health")
 def handle(self, **options):
     """Command implementation.
     """
     print dumps(health())
 def get(self, _request, response, _app, _model):
     """Return the current queue health.
     """
     response['health'] = health()