Exemple #1
0
    def test_create_and_cancel(self):
        # Create 3 meaningless jobs. We're just testing job setup and
        # cancellation here, not the execution.
        utils.async_get_result_rows(None, None, {})
        job_options = {
            'name': 'Job X',
        }
        job_x_id = utils.async_get_result_rows(None, None, {}, job_options)
        job_options = {
            'name': 'Job Y',
            'query_name': 'job_y_query',
        }
        job_y_id = utils.async_get_result_rows(None, None, {}, job_options)

        self.assertEqual(async_utils.get_job_count(), 3)

        jobs = async_utils.get_jobs()
        self.assertEqual(len(jobs), 3)

        job_x = async_utils.get_job(job_x_id)
        self.assertTrue(job_x in jobs)
        self.assertEqual(job_x.meta['name'], 'Job X')

        self.assertEqual(async_utils.cancel_job(job_x_id), None)
        self.assertEqual(async_utils.get_job_count(), 2)
        async_utils.cancel_job('invalid_id')
        self.assertEqual(async_utils.get_job_count(), 2)

        self.assertTrue('canceled' in async_utils.cancel_job(job_y_id))
        self.assertTrue(async_utils.get_job_count(), 1)

        async_utils.cancel_all_jobs()
        self.assertEqual(async_utils.get_job_count(), 0)
Exemple #2
0
    def test_create_and_cancel(self):
        # Create 3 meaningless jobs. We're just testing job setup and
        # cancellation here, not the execution.
        utils.async_get_result_rows(None, None, {})
        job_options = {
            'name': 'Job X',
        }
        job_x_id = utils.async_get_result_rows(None, None, {}, job_options)
        job_options = {
            'name': 'Job Y',
            'query_name': 'job_y_query',
        }
        job_y_id = utils.async_get_result_rows(None, None, {}, job_options)

        self.assertEqual(async_utils.get_job_count(), 3)

        jobs = async_utils.get_jobs()
        self.assertEqual(len(jobs), 3)

        job_x = async_utils.get_job(job_x_id)
        self.assertTrue(job_x in jobs)
        self.assertEqual(job_x.meta['name'], 'Job X')

        self.assertEqual(async_utils.cancel_job(job_x_id), None)
        self.assertEqual(async_utils.get_job_count(), 2)
        async_utils.cancel_job('invalid_id')
        self.assertEqual(async_utils.get_job_count(), 2)

        self.assertTrue('canceled' in async_utils.cancel_job(job_y_id))
        self.assertTrue(async_utils.get_job_count(), 1)

        async_utils.cancel_all_jobs()
        self.assertEqual(async_utils.get_job_count(), 0)
Exemple #3
0
    def get(self, request, export_type, **kwargs):
        view = self.get_view(request)
        context = self.get_context(request)
        params = self.get_params(request)

        # Configure the query options used for retrieving the results.
        query_options = {
            'export_type': export_type,
            'query_name': self._get_query_name(request, export_type),
        }
        query_options.update(**kwargs)
        query_options.update(params)

        job_data = {
            'query_name': self._get_query_name(request, export_type),
            'user_name': request.user.username,
            'session_key': request.session.session_key,
            'result_processor': ASYNC_EXPORTER_RESULT_PROCESSOR_NAME
        }

        job_id = async_get_result_rows(
            context, view, query_options, job_data)

        return HttpResponseRedirect(
            reverse('serrano:jobs:single', kwargs={'job_uuid': job_id}))
Exemple #4
0
    def get(self, request, **kwargs):
        params = self.get_params(request)

        # Configure the query options used for retrieving the results.
        query_options = {
            'export_type': JSONExporter.short_name.lower(),
            'query_name': self._get_query_name(request),
        }
        query_options.update(**kwargs)
        query_options.update(params)

        job_data = {
            'query_name': self._get_query_name(request),
            'user_name': request.user.username,
            'session_key': request.session.session_key,
            'result_processor': ASYNC_QUERY_RESULT_PROCESSOR_NAME
        }

        job_id = async_get_result_rows(
            request.instance.context,
            request.instance.view,
            query_options,
            job_data)

        return HttpResponseRedirect(
            reverse('serrano:jobs:single', kwargs={'job_uuid': job_id}))
Exemple #5
0
    def get(self, request, **kwargs):
        # Get the request's view and context
        view = self.get_view(request)
        context = self.get_context(request)

        # Configure the query options used for retrieving the results.
        query_options = {
            'export_type': HTMLExporter.short_name,
            'query_name': self._get_query_name(request),
        }
        query_options.update(**kwargs)
        query_options.update(self.get_params(request))

        job_data = {
            'query_name': self._get_query_name(request),
            'user_name': request.user.username,
            'session_key': request.session.session_key,
            'result_processor': ASYNC_PREVIEW_RESULT_PROCESSOR_NAME
        }

        job_id = async_get_result_rows(
            context, view, query_options, job_data, request=request)

        return HttpResponseRedirect(
            reverse('serrano:jobs:single', kwargs={'job_uuid': job_id}))
Exemple #6
0
    def get(self, request, **kwargs):
        params = self.get_params(request)

        # Configure the query options used for retrieving the results.
        query_options = {
            'export_type': JSONExporter.short_name.lower(),
            'query_name': self._get_query_name(request),
        }
        query_options.update(**kwargs)
        query_options.update(params)

        job_data = {
            'query_name': self._get_query_name(request),
            'user_name': request.user.username,
            'session_key': request.session.session_key,
            'result_processor': ASYNC_QUERY_RESULT_PROCESSOR_NAME
        }

        job_id = async_get_result_rows(
            request.instance.context,
            request.instance.view,
            query_options,
            job_data,
            request=request)

        return HttpResponseRedirect(
            reverse('serrano:jobs:single', kwargs={'job_uuid': job_id}))
Exemple #7
0
    def test_create_and_cancel(self):
        # Create 3 meaningless jobs. We're just testing job setup and
        # cancellation here, not the execution.
        job_options = {
            'name': 'Job X',
        }
        job_x_id = utils.async_get_result_rows(None, None, {}, job_options)
        job_options = {
            'name': 'Job Y',
            'query_name': 'job_y_query',
        }
        job_y_id = utils.async_get_result_rows(None, None, {}, job_options)
        job_z_id = utils.async_get_result_rows(None, None, {})

        self.assertEqual(async_utils.get_job_count(), 3)

        jobs = async_utils.get_jobs()
        self.assertEqual(len(jobs), 3)

        job_x = async_utils.get_job(job_x_id)
        self.assertTrue(job_x in jobs)
        self.assertEqual(job_x.meta['name'], 'Job X')

        job_y = async_utils.get_job(job_y_id)
        job_z = async_utils.get_job(job_z_id)

        self.assertEqual(async_utils.cancel_job(job_x_id), None)
        # Prove job is gone from Redis
        with self.assertRaises(NoSuchJobError):
            job_x.refresh()
        # Prove job is gone from queue
        self.assertEqual(async_utils.get_job_count(), 2)
        async_utils.cancel_job('invalid_id')
        self.assertEqual(async_utils.get_job_count(), 2)

        self.assertTrue('canceled' in async_utils.cancel_job(job_y_id))
        self.assertTrue(async_utils.get_job_count(), 1)

        async_utils.cancel_all_jobs()
        with self.assertRaises(NoSuchJobError):
            job_y.refresh()
        with self.assertRaises(NoSuchJobError):
            job_z.refresh()
        self.assertEqual(async_utils.get_job_count(), 0)
Exemple #8
0
    def test_invalid_job_result(self):
        context = DataContext()
        view = DataView()
        query_options = {
            'page': 0,
        }

        job_id = utils.async_get_result_rows(context, view, query_options)
        self.assertTrue(async_utils.get_job_count(), 1)
        async_utils.run_jobs()
        time.sleep(1)
        self.assertEqual(async_utils.get_job_result(job_id), None)
        self.assertEqual(async_utils.get_job(job_id).status, JobStatus.FAILED)
Exemple #9
0
    def test_invalid_job_result(self):
        context = DataContext()
        view = DataView()
        query_options = {
            'page': 0,
        }

        job_id = utils.async_get_result_rows(context, view, query_options)
        self.assertTrue(async_utils.get_job_count(), 1)
        async_utils.run_jobs()
        time.sleep(1)
        self.assertEqual(async_utils.get_job_result(job_id), None)
        self.assertEqual(async_utils.get_job(job_id).status, JobStatus.FAILED)
Exemple #10
0
    def test_job_result(self):
        context = DataContext()
        view = DataView()
        limit = 3
        query_options = {
            'limit': limit,
            'page': 1,
        }

        job_id = utils.async_get_result_rows(context, view, query_options)
        self.assertTrue(async_utils.get_job_count(), 1)
        async_utils.run_jobs()
        time.sleep(1)
        result = async_utils.get_job_result(job_id)
        self.assertEqual(async_utils.get_job(job_id).status,
                         JobStatus.FINISHED)
        self.assertEqual(len(result['rows']), limit)
        self.assertEqual(result['limit'], limit)
Exemple #11
0
    def test_job_result(self):
        context = DataContext()
        view = DataView()
        limit = 3
        query_options = {
            'limit': limit,
            'page': 1,
        }

        job_id = utils.async_get_result_rows(context, view, query_options)
        self.assertTrue(async_utils.get_job_count(), 1)
        async_utils.run_jobs()
        time.sleep(1)
        result = async_utils.get_job_result(job_id)
        self.assertEqual(
            async_utils.get_job(job_id).status, JobStatus.FINISHED)
        self.assertEqual(len(result['rows']), limit)
        self.assertEqual(result['limit'], limit)