def job_view(request, job_id): job = get_object_or_404(Job, pk=job_id) status = error = output = paginator = refresh = None try: with client.connect() as service: status = service.getStatus(job.backend_id) except NotFoundException as ex: error = WMRError(ex, title='Job Expired', message='This job has expired, and is unavailable.') except InternalException as ex: error = WMRBackendInternalError(ex) except TException as ex: error = WMRThriftError(ex) else: # Update cached job status job.update_status(status) job.save() # Determine whether or not a job is finished status.is_finished = (status.state == State.SUCCESSFUL or status.state == State.KILLED or status.state == State.FAILED) if not status.is_finished: if datetime.datetime.now() - job.submit_time > datetime.timedelta( minutes=5): refresh = 15 else: refresh = 5 # Retrieve output page if appropriate if (status.state == State.SUCCESSFUL and status.reduceStatus and status.reduceStatus.output is None and status.info and status.info.outputPath): # Check for page from request try: if 'page' in request.GET: page = int(request.GET['page']) else: page = 1 except ValueError: page = 1 # Fetch page try: with client.connect() as service: data_page = service.readDataPage(status.info.outputPath, page) except (NotFoundException, PermissionException) as ex: error = WMRError(ex) except InternalException as ex: error = WMRBackendInternalError(ex) except TException as ex: error = WMRThriftError(ex) else: if data_page.totalPages == 0: output = { 'data': '[Empty]', 'paginator': SimplePaginator(page, 1), } else: paginator = SimplePaginator(page, data_page.totalPages) output = { 'data': data_page.data, 'paginator': paginator, } # Set human-readable state values if status.state: status.state_display = STATE_DISPLAYS[status.state] if status.mapStatus and status.mapStatus.state: status.mapStatus.state_display = \ STATE_DISPLAYS[status.mapStatus.state] if status.reduceStatus and status.reduceStatus.state: status.reduceStatus.state_display = \ STATE_DISPLAYS[status.reduceStatus.state] # Create a configuration that re-uses the input recycle = Configuration() recycle.language = job.config.language recycle.name = job.config.name recycle.input = job.config.input return render_to_response( 'wmr/job_view.html', RequestContext( request, { 'job': job, 'status': status, 'output': output, 'error': error, 'refresh': refresh, }))