def info(job_id): with session_query() as session: job = Job.load(job_id, session) frontend_scan_id = job.scan.scan_id filename = job.filename probe = job.probename return (frontend_scan_id, filename, probe)
def scan(file, probelist, frontend_scan): try: with session_transaction() as session: log.debug("scan_id: %s fileweb_id: %s received %s", frontend_scan, file, probelist) user = User.get_by_rmqvhost(session) scan = scan_ctrl.new(frontend_scan, user, session) # Now, create one subtask per file to scan per probe new_jobs = [] for probe in probelist: if probe in probe_ctrl.available_probes: j = Job(scan.id, file, probe) session.add(j) new_jobs.append(j) else: # send an error message to not stuck the scan # One probe asked is no more present res = probe_ctrl.create_error_results( probe, "missing probe", session) celery_frontend.scan_result(file, probe, res) session.commit() scan_ctrl.launch(scan, new_jobs, session) log.info( "scan_id %s: file %s received / %d active probe(s) / " "%d job(s) launched", scan.scan_id, file, len(probe_ctrl.available_probes), len(scan.jobs)) except Exception as e: log.exception(type(e).__name__ + " : " + str(e)) raise
def scan(frontend_scanid, scan_request_dict): try: with session_transaction() as session: log.debug("scanid: %s received %s", frontend_scanid, scan_request_dict) user = User.get_by_rmqvhost(session) scan_request = IrmaScanRequest(scan_request_dict) scan = scan_ctrl.new(frontend_scanid, user, scan_request.nb_files, session) available_probelist = probe_ctrl.get_list(session) # Now, create one subtask per file to # scan per probe new_jobs = [] for filehash in scan_request.filehashes(): probelist = scan_request.get_probelist(filehash) scan_ctrl.check_probelist(scan, probelist, available_probelist, session) for probe in probelist: j = Job(scan.id, filehash, probe) session.add(j) new_jobs.append(j) session.commit() scan_ctrl.launch(scan, new_jobs, session) celery_frontend.scan_launched(scan.scan_id, scan_request.to_dict()) log.info( "scanid %s: %d file(s) received / %d active probe(s) / " "%d job(s) launched", scan.scan_id, scan.nb_files, len(available_probelist), len(scan.jobs)) except Exception as e: log.exception(e) raise
def _finish(job_id, status): with session_transaction() as session: job = Job.load(job_id, session) job.status = status job.ts_end = timestamp() job.update(['status', 'ts_end'], session) scan_id = job.scan.id scanctrl.check_finished(scan_id)
def test001___init__(self): job = Job(self.scan_id, self.filehash, self.probename) self.assertEqual(job.scan_id, self.scan_id) self.assertEqual(job.filehash, self.filehash) self.assertEqual(job.probename, self.probename) self.assertIsNotNone(job.task_id)
def duration(job_id): with session_query() as session: job = Job.load(job_id, session) return (job.ts_end - job.ts_start)
def set_taskid(job_id, task_id): with session_transaction() as session: job = Job.load(job_id, session) job.task_id = task_id
def new(scan_id, filename, probe, task_id): with session_transaction() as session: j = Job(filename, probe, scan_id, task_id) j.save(session) session.commit() return j.id