本文整理汇总了Python中jobbrowser.models.Job类的典型用法代码示例。如果您正苦于以下问题:Python Job类的具体用法?Python Job怎么用?Python Job使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Job类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: kill_job
def kill_job(request, jobid):
"""
We get here from /jobs/jobid/kill
"""
if request.method != "POST":
raise Exception(_("kill_job may only be invoked with a POST (got a %(method)s)") % dict(method=request.method))
job = Job.from_id(jt=request.jt, jobid=jobid)
if job.user != request.user.username and not request.user.is_superuser:
access_warn(request, _('Insufficient permission'))
raise MessageException(_("Permission denied. User %(username)s cannot delete user %(user)s's job.") %
dict(username=request.user.username, user=job.user))
job.kill()
cur_time = time.time()
while time.time() - cur_time < 15:
job = Job.from_id(jt=request.jt, jobid=jobid)
if job.status not in ["RUNNING", "QUEUED"]:
if request.REQUEST.get("next"):
return HttpResponseRedirect(request.REQUEST.get("next"))
else:
raise MessageException("Job Killed")
time.sleep(1)
job = Job.from_id(jt=request.jt, jobid=jobid)
raise Exception(_("Job did not appear as killed within 15 seconds"))
示例2: kill_job
def kill_job(request, job):
if request.method != "POST":
raise Exception(_("kill_job may only be invoked with a POST (got a %(method)s).") % dict(method=request.method))
if job.user != request.user.username and not request.user.is_superuser:
access_warn(request, _('Insufficient permission'))
raise MessageException(_("Permission denied. User %(username)s cannot delete user %(user)s's job.") %
dict(username=request.user.username, user=job.user))
job.kill()
cur_time = time.time()
while time.time() - cur_time < 15:
job = Job.from_id(jt=request.jt, jobid=job.jobId)
if job.status not in ["RUNNING", "QUEUED"]:
if request.REQUEST.get("next"):
return HttpResponseRedirect(request.REQUEST.get("next"))
elif request.REQUEST.get("format") == "json":
return HttpResponse(encode_json_for_js({'status': 0}), mimetype="application/json")
else:
raise MessageException("Job Killed")
time.sleep(1)
job = Job.from_id(jt=request.jt, jobid=job.jobId)
raise Exception(_("Job did not appear as killed within 15 seconds."))
示例3: job_single_logs
def job_single_logs(request, jobid):
"""
We get here from /jobs/jobid/logs
"""
job = Job.from_id(jt=request.jt, jobid=jobid)
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]
else:
recent_tasks = job.filter_tasks(task_states=('running', 'succeeded',), task_types=('map', 'reduce',))
recent_tasks.sort(cmp_exec_time, reverse=True)
if recent_tasks:
task = recent_tasks[0]
if task is None:
raise PopupException(_("No tasks found for job %(id)s") % dict(id=jobid))
return single_task_attempt_logs(request, **{'jobid': jobid, 'taskid': task.taskId, 'attemptid': task.taskAttemptIds[-1]})
示例4: get_matching_jobs
def get_matching_jobs(request, **kwargs):
"""
Returns an array of jobs where the returned
jobs are matched by the provided filter arguments.
If a filter argument is in kwargs it will supersede the same argument
in the request object.
Filter arguments may be jobid, pools, user, tasks, text and state.
"""
jobfunc = {
"completed": request.jt.completed_jobs,
# Succeeded and completed are synonyms here.
"succeeded": request.jt.completed_jobs,
"running": request.jt.running_jobs,
"failed": request.jt.failed_jobs,
"killed": request.jt.killed_jobs,
"all": request.jt.all_jobs
}
if 'state' in kwargs:
selection = kwargs['state']
else:
selection = request.GET.get("state", "all")
joblist = jobfunc[selection]().jobs
return [
Job.from_thriftjob(request.jt, j)
for j in _filter_jobs_by_req(joblist, request, **kwargs)
]
示例5: get_matching_jobs
def get_matching_jobs(request, check_permission=False, **kwargs):
"""
Returns an array of jobs where the returned
jobs are matched by the provided filter arguments.
If a filter argument is in kwargs it will supersede the same argument
in the request object.
Filter arguments may be jobid, pools, user, tasks, text and state.
Filter by user ownership if check_permission is set to true.
"""
jobfunc = {"completed" : (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
# Succeeded and completed are synonyms here.
"succeeded" : (request.jt.completed_jobs, ThriftJobState.SUCCEEDED),
"running" : (request.jt.running_jobs, ThriftJobState.RUNNING),
"failed" : (request.jt.failed_jobs, ThriftJobState.FAILED),
"killed" : (request.jt.killed_jobs, ThriftJobState.KILLED),
"all" : (request.jt.all_jobs, None)}
if 'state' in kwargs:
selection = kwargs['state']
else:
selection = request.GET.get("state", "all")
joblist = jobfunc[selection][0]().jobs + request.jt.retired_jobs(jobfunc[selection][1]).jobs
return [Job.from_thriftjob(request.jt, j)
for j in _filter_jobs_by_req(joblist, request, **kwargs)
if not check_permission or request.user.is_superuser or j.profile.user == request.user]
示例6: filter_jobs
def filter_jobs(self, user, jobs, **kwargs):
check_permission = not SHARE_JOBS.get() and not user.is_superuser
limit = kwargs.pop('limit', 10000)
return [Job.from_thriftjob(self.jt, j)
for j in self._filter_jobs(jobs, **kwargs)
if not check_permission or user.is_superuser or j.profile.user == user.username][:limit]
示例7: decorate
def decorate(request, *args, **kwargs):
jobid = kwargs['jobid']
job = Job.from_id(jt=request.jt, jobid=jobid)
if not conf.SHARE_JOBS.get() and not request.user.is_superuser \
and job.user != request.user.username:
raise PopupException(_("You don't have the permissions to access"
" job %(id)s") % dict(id=jobid))
return view_func(request, *args, **kwargs)
示例8: kill_job
def kill_job(request, jobid):
"""
We get here from /jobs/jobid/kill
"""
if request.method != "POST":
raise Exception("kill_job may only be invoked with a POST (got a %s)" % request.method)
job = Job.from_id(jt=request.jt, jobid=jobid)
if job.user != request.user.username and not request.user.is_superuser:
access_warn(request, 'Insufficient permission')
raise MessageException("Permission denied. User %s cannot delete user %s's job." %
(request.user.username, job.profile.user))
job.kill()
cur_time = time.time()
while time.time() - cur_time < 15:
job = Job.from_id(jt=request.jt, jobid=jobid)
if job.status not in ["RUNNING", "QUEUED"]:
return render_json({})
time.sleep(1)
job = Job.from_id(jt=request.jt, jobid=jobid)
raise Exception("Job did not appear as killed within 15 seconds")
示例9: single_job
def single_job(request, jobid):
"""
We get here from /jobs/jobid
"""
job = Job.from_id(jt=request.jt, jobid=jobid)
def cmp_exec_time(task1, task2):
return cmp(task1.execStartTimeMs, task2.execStartTimeMs)
failed_tasks = job.filter_tasks(task_states=("failed",))
failed_tasks.sort(cmp_exec_time)
recent_tasks = job.filter_tasks(task_states=("running", "succeeded"))
recent_tasks.sort(cmp_exec_time, reverse=True)
return render(
"job.mako",
request,
{"request": request, "job": job, "failed_tasks": failed_tasks[:5], "recent_tasks": recent_tasks[:5]},
)
示例10: single_job
def single_job(request, jobid):
"""
We get here from /jobs/jobid
"""
job = Job.from_id(jt=request.jt, jobid=jobid)
def cmp_exec_time(task1, task2):
return cmp(task1.execStartTimeMs, task2.execStartTimeMs)
failed_tasks = job.filter_tasks(task_states=('failed',))
failed_tasks.sort(cmp_exec_time)
recent_tasks = job.filter_tasks(task_states=('running', 'succeeded',))
recent_tasks.sort(cmp_exec_time, reverse=True)
return render("job.mako", request, {
'request': request,
'job': job,
'failed_tasks': failed_tasks[:5],
'recent_tasks': recent_tasks[:5]
})
示例11: get_job
def get_job(self, jobid):
return Job.from_id(jt=self.jt, jobid=jobid)
示例12: job_counters
def job_counters(request, jobid):
"""
We get here from /jobs/jobid/counters
"""
job = Job.from_id(jt=request.jt, jobid=jobid)
return render("counters.html", request, {"counters":job.counters})
示例13: get_single_job
def get_single_job(request, jobid):
"""
Returns the job which matches jobid.
"""
return Job.from_id(jt=request.jt, jobid=jobid)