Commit b967254f authored by Lauren Adoram-Kershner's avatar Lauren Adoram-Kershner Committed by jlaura
Browse files

adding queue length and clearing functionality to NCG (#393)

* adding queue length and clearing functionality to NCG

* addressing jays comments
parent 3e6b670b
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -1861,3 +1861,28 @@ WHERE
    def measures(self):
        df = pd.read_sql_table('measures', con=engine)
        return df

    @property
    def queue_length(self):
        """
        Returns the length of the processing queue. Jobs are left on the
        queue if a cluster job is cancelled. Those cancelled jobs are then
        called on next cluster job launch, causing failures. This method provides
        a quick check for left over jobs.
        """
        conf = config['redis']
        queue = StrictRedis(host=conf['host'],
                            port=conf['port'])
        llen = queue.llen(conf['processing_queue'])
        return llen

    @staticmethod
    def queue_flushdb(self):
        """
        Clear the processing queue of any left over jobs from a previous cluster
        job cancellation or hanging jobs.
        """
        conf = config['redis']
        queue = StrictRedis(host=conf['host'],
                            port=conf['port'])
        queue.flushdb()