def jobs_render(): session.forget(response) if request.vars.job_name: q = sd.job_name == request.vars.job_name all_jobs = {request.vars.job_name: 'a_0'} newjob = None else: q = sd.id > 0 all_jobs = dbs(q).select(sd.job_name, groupby=sd.job_name) all_jobs = dict([(row.job_name, "a_%s" % k) for k, row in enumerate(all_jobs)]) newjob = str(int(time.mktime(datetime.datetime.utcnow().timetuple()))) all_deps = dbs(q).select() all_nodes = {} all_edges = {} for row in all_deps: jname_slug = all_jobs[row.job_name] if jname_slug not in all_nodes: all_nodes[jname_slug] = {} all_nodes[jname_slug][row.task_parent] = None all_nodes[jname_slug][row.task_child] = None if jname_slug not in all_edges: all_edges[jname_slug] = [] all_edges[jname_slug].append( (row.task_child, row.task_parent, dict(style="stroke: %s" % (row.can_visit and '#5CB85C' or '#D9534F')))) all_tasks_ids = {} for k, v in all_nodes.iteritems(): for id in v.keys(): all_tasks_ids[id] = None all_tasks_labels = dbs(st.id.belongs(all_tasks_ids.keys())).select( st.id, st.function_name, st.task_name, st.status).as_dict() for k, v in all_nodes.iteritems(): for id in v.keys(): all_nodes[k][id] = dict( label=all_tasks_labels[id]['task_name'], style="fill: %s;" % graph_colors_task_status(all_tasks_labels[id]['status']), title="%(id)s (%(function_name)s): %(status)s" % all_tasks_labels[id], linkto=URL('task_details', args=id, user_signature=True)) return dict(all_jobs=all_jobs, all_edges=dumps(all_edges), all_nodes=dumps(all_nodes), newjob=newjob)
def jobs_render(): session.forget(response) if request.vars.job_name: q = sd.job_name == request.vars.job_name all_jobs = {request.vars.job_name : 'a_0'} newjob = None else: q = sd.id > 0 all_jobs = dbs(q).select(sd.job_name, groupby=sd.job_name) all_jobs = dict([(row.job_name, "a_%s" % k) for k, row in enumerate(all_jobs)]) newjob = str(int(time.mktime(datetime.datetime.utcnow().timetuple()))) all_deps = dbs(q).select() all_nodes = {} all_edges = {} for row in all_deps: jname_slug = all_jobs[row.job_name] if jname_slug not in all_nodes: all_nodes[jname_slug] = {} all_nodes[jname_slug][row.task_parent] = None all_nodes[jname_slug][row.task_child] = None if jname_slug not in all_edges: all_edges[jname_slug] = [] all_edges[jname_slug].append((row.task_child, row.task_parent, dict(style="stroke: %s" % (row.can_visit and '#5CB85C' or '#D9534F')))) all_tasks_ids = {} for k, v in all_nodes.iteritems(): for id in v.keys(): all_tasks_ids[id] = None all_tasks_labels = dbs(st.id.belongs(all_tasks_ids.keys())).select( st.id, st.function_name, st.task_name, st.status ).as_dict() for k, v in all_nodes.iteritems(): for id in v.keys(): all_nodes[k][id] = dict(label=all_tasks_labels[id]['task_name'], style="fill: %s;" % graph_colors_task_status(all_tasks_labels[id]['status']), title="%(id)s (%(function_name)s): %(status)s" % all_tasks_labels[id], linkto=URL('task_details', args=id, user_signature=True)) return dict(all_jobs=all_jobs, all_edges=dumps(all_edges), all_nodes=dumps(all_nodes), newjob=newjob)
def tasks_dropdown_helper(): session.forget(response) if not request.get_vars.q: raise HTTP(404) q = request.get_vars.q all_tasks = dbs((st.task_name.ilike('%' + q + '%')) | (st.id.ilike('%' + q + '%'))).select( st.id, st.task_name) rtn = [] for row in all_tasks: rtn.append(dict(id=row.id, text='%(id)s - %(task_name)s' % row)) return dumps(dict(results=rtn))
def tasks_dropdown_helper(): session.forget(response) if not request.get_vars.q: raise HTTP(404) q = request.get_vars.q all_tasks = dbs( (st.task_name.ilike('%' + q + '%')) | (st.id.ilike('%' + q + '%')) ).select( st.id, st.task_name ) rtn = [] for row in all_tasks: rtn.append(dict(id=row.id, text='%(id)s - %(task_name)s' % row)) return dumps(dict(results=rtn))
def analyze_task(): task_id = request.args(0) if not task_id: return '' task = dbs(st.id == task_id).select().first() if not task: return '' q = sr.task_id == task_id first_run = dbs(q).select(sr.start_time, orderby=sr.start_time, limitby=(0,1)).first() last_run = dbs(q).select(sr.start_time, orderby=~sr.start_time, limitby=(0,1)).first() if not first_run: mode = 'no_runs' #we can rely on the data on the scheduler_task table because no scheduler_run were found q = st.id == task_id else: mode = 'runs' if len(request.args) >= 2: if request.args(1) == 'byfunction': if mode == 'runs': q = sr.task_id.belongs(dbs(st.function_name == task.function_name)._select(st.id)) else: q = st.function_name == task.function_name elif request.args(1) == 'bytaskname': if mode == 'runs': q = sr.task_id.belongs(dbs(st.task_name == task.task_name)._select(st.id)) else: q = st.task_name == task.task_name elif request.args(1) == 'this': if mode == 'runs': q = sr.task_id == task_id else: q = st.id == task_id if len(request.args) == 4 and request.args(2) == 'byday': daysback = int(request.args(3)) now = s.utc_time and request.utcnow or request.now day = now.date() - timed(days=daysback) if mode == 'runs': q = q & ((sr.start_time >= day) & (sr.start_time < day + timed(days=1))) else: q = q & ((st.last_run_time >= day) & (st.last_run_time < day + timed(days=1))) if mode == 'runs': gb_duration_rows, jgb_duration_series = gb_duration(q) jgb_duration_series = dumps(jgb_duration_series) else: #no duration can be calculated using the scheduler_task table only jgb_duration_series = dumps([]) gb_status_rows, jgb_status_series = gb_status(q, mode) jgb_status_series = dumps(jgb_status_series) gb_when_rows, jgb_when_series = bydate(q, mode) jgb_when_series = dumps(jgb_when_series) if len(request.args) == 4 and request.args(2) == 'byday': gb_whend_rows, jgb_whend_series = byday(q, day, mode) jgb_whend_series = dumps(jgb_whend_series) else: jgb_whend_series = dumps([[]]) return locals()