Example #1
0
def run_job(self, job_name, inputs):
    job_info = REGISTERED_JOBS[job_name]
    results_renderer = job_info.get('results_renderer')

    if isinstance(results_renderer, six.string_types):
        try:
            module_name, class_name = results_renderer.rsplit('.', 1)
            module = import_module(module_name)
            results_renderer = getattr(module, class_name)
        except (ImportError, ValueError, AttributeError):
            raise ImproperlyConfigured('Could not import {}'.format(results_renderer))

    if not any((results_renderer is None, callable(results_renderer), isinstance(results_renderer, RasterRenderer))):
        raise ImproperlyConfigured('Invalid renderer: {}'.format(results_renderer))

    t = get_task_instance(job_name)
    results = t(**process_web_inputs(t, copy.copy(inputs)))
    publish_raster_results = job_info.get('publish_raster_results', False)

    job = ProcessingJob.objects.get(celery_id=self.request.id)
    job.outputs=json.dumps(process_web_outputs(results, job, publish_raster_results, results_renderer))
    job.save()