@check_job_permission
def job_single_logs(request, job, offset=LOG_OFFSET_BYTES):
 def cmp_exec_time(task1, task2):
  return cmp(task1.execStartTimeMs, task2.execStartTimeMs)
 task = None
 failed_tasks = job.filter_tasks(task_states=('failed',))
 failed_tasks.sort(cmp_exec_time)
 if failed_tasks:
  task = failed_tasks[0]
  if ((not task.taskAttemptIds) and (len(failed_tasks) > 1)):
   task = failed_tasks[1]
 else:
  task_states = ['running', 'succeeded']
  if job.is_mr2:
   task_states.append('scheduled')
  recent_tasks = job.filter_tasks(task_states=task_states, task_types=('map', 'reduce'))
  recent_tasks.sort(cmp_exec_time, reverse=True)
  if recent_tasks:
   task = recent_tasks[0]
 if ((task is None) or (not task.taskAttemptIds)):
  raise PopupException((_('No tasks found for job %(id)s.') % {'id': job.jobId}))
 params = {'job': job.jobId, 'taskid': task.taskId, 'attemptid': task.taskAttemptIds[(-1)], 'offset': offset}
 return single_task_attempt_logs(request, **params)

@ check_job_permission def job_single_logs ( request , job , offset = LOG_OFFSET_BYTES ) : def cmp_exec_time ( task1 , task2 ) : return cmp ( task1 . execStartTimeMs , task2 . execStartTimeMs ) task = None failed_tasks = job . filter_tasks ( task_states = ( 'failed' , ) ) failed_tasks . sort ( cmp_exec_time ) if failed_tasks : task = failed_tasks [ 0 ] if ( ( not task . taskAttemptIds ) and ( len ( failed_tasks ) > 1 ) ) : task = failed_tasks [ 1 ] else : task_states = [ 'running' , 'succeeded' ] if job . is_mr2 : task_states . append ( 'scheduled' ) recent_tasks = job . filter_tasks ( task_states = task_states , task_types = ( 'map' , 'reduce' ) ) recent_tasks . sort ( cmp_exec_time , reverse = True ) if recent_tasks : task = recent_tasks [ 0 ] if ( ( task is None ) or ( not task . taskAttemptIds ) ) : raise PopupException ( ( _ ( 'No tasks found for job %(id)s.' ) % { 'id' : job . jobId } ) ) params = { 'job' : job . jobId , 'taskid' : task . taskId , 'attemptid' : task . taskAttemptIds [ ( - 1 ) ] , 'offset' : offset } return single_task_attempt_logs ( request , ** params )
try to smartly detect the most useful task attempt and get its mr logs .