def test_listRunning(self): arr = [("ready", Job.READY), ("running", Job.RUNNING), ("finished", Job.FINISHED), ("running", Job.RUNNING)] for name, status in arr: job = Job.create(db.session, **self.opts) job.name = name job.status = status db.session.commit() jobs = Job.listRunning(db.session) self.assertEqual(len(jobs), 2) self.assertEqual([x.status for x in jobs], [Job.RUNNING, Job.RUNNING])
def start(): session = SignallingSession(db) session.begin(subtransactions=True) # We fetch all jobs for the queue when invoked jobs = Job.listRunning(session) scheduler.logger.info("Fetched %s jobs to analyze", len(jobs)) running = [x for x in jobs if x.status == Job.RUNNING] for x in running: x.status = Job.CLOSED session.commit() scheduler.logger.info("Running job '%s' is closed, cannot resolve process id", x.uid) session.commit() session.close() # Start sampler sampler.start() scheduler.logger.info("Job scheduler is started, refresh interval = %s, number of slots = %s", REFRESH_INTERVAL, NUM_SLOTS)