def get_session_info(session_id): session = get_session(g.db, session_id) build_uuid = session_id.split('-')[0] build = Build.load(build_uuid) recipe = Recipe.load(build.recipe, build.recipe_ref) job = Job.load(build.job_name, build.job_ref) # Calculate the actual parameters - setting defaults if static value. # (parameters that have a function as default value will have them # called just before starting the job) param_def = job.get_merged_params() parameters = build.parameters for name in param_def: param = param_def[name] if 'default' in param and not name in parameters: parameters[name] = param['default'] return jsonify(run_info=session['run_info'] or {}, build_uuid=build_uuid, build_name="%s-%d" % (build.job_name, build.number), recipe=recipe.contents, ss_token=build.ss_token, ss_url=current_app.config['SS_URL'], parameters=parameters)
def put_job_raw(name): raw = request.json['yaml'] job = Job.parse(name, raw) try: job.save(prev_ref=request.json.get('old')) except JobNotCurrent: abort(412) return jsonify(ref=job.ref)
def create_job(name): job = Job.parse(name, "recipe: %s" % request.json.get('recipe')) try: job.save() except JobNotCurrent: print("Job already exists!") abort(412) return jsonify(ref=job.ref)
def do_create_build(job_name): input = request.json job = Job.load(job_name, input.get('job_ref')) build = Build.create(job, parameters=input.get('parameters', {}), description=input.get('description', '')) return jsonify(**build)
def do_start_build(job_name): input = request.json job = Job.load(job_name, input.get('job_ref')) build = Build.create(job, parameters=input.get('parameters', {}), description=input.get('description', '')) session_id = '%s-0' % build.uuid set_session_queued(g.db, session_id) r = ResQ() r.enqueue(DispatchSession, session_id) return jsonify(**build.as_dict())
def get_job(name): try: job = Job.load(name, ref=request.args.get('ref')) except JobNotFound: abort(404) blen = job.latest_build history = [] if request.args.get('history'): fields = ('#', 'build:*->number', 'build:*->created', 'build:*->description', 'build:*->build_id', 'build:*->state', 'build:*->result') for d in chunks( g.db.sort(KEY_JOB_BUILDS % name, start=blen - 10, num=10, by='nosort', get=fields), 7): history.append( dict(number=int(d[1]), created=d[2], description=d[3], build_id=d[4] or None, state=d[5], result=d[6])) history.reverse() yaml_str = job.yaml if request.args.get('yaml') else None return jsonify(name=job.name, ref=job.ref, recipe=job.recipe, recipe_ref=job.recipe_ref, description=job.description, tags=job.tags, success_no=job.last_success, latest_no=blen, history=history, parameters=job.parameters, merged_params=job.get_merged_params(), yaml=yaml_str)
def DoJobDone(db, build_uuid, session_no, li): job_name = Build.get_job_name(build_uuid) Job.set_last_success(job_name, build_uuid)