def test__submit_job_minimal(app): """Test fast mode job submission works as expected""" fake_db = get_db() queue = app.config['FAST_QUEUE'] assert app.config['FAKE_DB'] old_len = fake_db.llen(queue) job = Job(fake_db, 'taxon-fake') job.minimal = True job.commit() utils._submit_job(fake_db, job, app.config) assert old_len + 1 == fake_db.llen(queue) fake_db.ltrim(app.config['DOWNLOAD_QUEUE'], 2, 1) # clear queue job = Job(fake_db, 'taxon-fake') job.minimal = True job.needs_download = True job.commit() utils._submit_job(fake_db, job, app.config) assert 1 == fake_db.llen(app.config['DOWNLOAD_QUEUE']) job.fetch() assert job.target_queues == [queue]
def dispatch_job(): """Internal helper to dispatch a new job""" redis_store = get_db() taxon = app.config['TAXON'] job_id = _generate_jobid(taxon) job = Job(redis_store, job_id) if 'X-Forwarded-For' in request.headers: job.ip_addr = request.headers.getlist("X-Forwarded-For")[0].rpartition( ' ')[-1] else: job.ip_addr = request.remote_addr or 'untrackable' ncbi = request.form.get('ncbi', '').strip() val = request.form.get('email', '').strip() if val: job.email = val job.minimal = _get_checkbox(request, 'minimal') job.all_orfs = _get_checkbox(request, 'all_orfs') job.smcogs = _get_checkbox(request, 'smcogs') job.clusterblast = _get_checkbox(request, 'clusterblast') job.knownclusterblast = _get_checkbox(request, 'knownclusterblast') job.subclusterblast = _get_checkbox(request, 'subclusterblast') job.cc_mibig = _get_checkbox(request, 'cc_mibig') job.jobtype = request.form.get('jobtype', app.config['DEFAULT_JOBTYPE']) if job.jobtype not in (app.config['LEGACY_JOBTYPE'], app.config['DEFAULT_JOBTYPE']): raise BadRequest(f"Invalid jobtype {job.jobtype}") genefinder = request.form.get('genefinder', '') if genefinder: job.genefinder = genefinder hmmdetection_strictness = request.form.get('hmmdetection_strictness', '') if hmmdetection_strictness: job.hmmdetection_strictness = hmmdetection_strictness val = request.form.get('from', 0, type=int) if val: job.from_pos = val val = request.form.get('to', 0, type=int) if val: job.to_pos = val job.asf = _get_checkbox(request, 'asf') job.tta = _get_checkbox(request, 'tta') job.cassis = _get_checkbox(request, 'cassis') job.clusterhmmer = _get_checkbox(request, 'clusterhmmer') job.pfam2go = _get_checkbox(request, 'pfam2go') job.rre = _get_checkbox(request, 'rre') job.tigrfam = _get_checkbox(request, 'tigrfam') dirname = path.join(app.config['RESULTS_PATH'], job.job_id, 'input') os.makedirs(dirname) if ncbi != '': if ' ' in ncbi: raise BadRequest("Spaces are not allowed in an NCBI ID.") job.download = ncbi job.needs_download = True else: upload = request.files['seq'] if upload is not None: filename = secure_filename(upload.filename) upload.save(path.join(dirname, filename)) if not path.exists(path.join(dirname, filename)): raise BadRequest("Could not save file!") job.filename = filename job.needs_download = False else: raise BadRequest("Uploading input file failed!") if 'gff3' in request.files: gff_upload = request.files['gff3'] if gff_upload is not None: gff_filename = secure_filename(gff_upload.filename) gff_upload.save(path.join(dirname, gff_filename)) if not path.exists(path.join(dirname, gff_filename)): raise BadRequest("Could not save GFF file!") job.gff3 = gff_filename if 'sideload' in request.files: sideload = request.files['sideload'] if sideload is not None: sideload_filename = secure_filename(sideload.filename) sideload.save(path.join(dirname, sideload_filename)) if not path.exists(path.join(dirname, sideload_filename)): raise BadRequest("Could not save sideload info file!") job.sideload = sideload_filename job.trace.append("{}-api".format(platform.node())) _submit_job(redis_store, job, app.config) _dark_launch_job(redis_store, job, app.config) return job