@classmethod
    def abandon_stale_jobs(cls):
        """
        On rare occasions, nommers crash so hard that no ``ERROR`` state change
        is made, and the job just gets stuck in a permanent unfinished state
        (``DOWNLOADING``, ``ENCODING``, ``UPLOADING``, etc). Rather than hang
        on to these indefinitely, abandon them by setting their state to
        ``ABANDONED``.

        The threshold for which jobs are considered abandoned is configurable
        via the
        :py:data:`FEEDERD_ABANDON_INACTIVE_JOBS_THRESH <media_nommer.conf.settings.FEEDERD_ABANDON_INACTIVE_JOBS_THRESH>`
        setting.
        """
        logger.debug("JobCache.abandon_stale_jobs(): "\
                     "Looking for stale jobs.")
        for id, job in cls.get_cached_jobs().items():
            if not job.is_finished():
                now_dtime = datetime.datetime.now()
                last_mod = job.last_modified_dtime

                tdelta = now_dtime - last_mod
                inactive_seconds = total_seconds(tdelta)

                if inactive_seconds >= settings.FEEDERD_ABANDON_INACTIVE_JOBS_THRESH:
                    cls.remove_job(job)
                    job.set_job_state('ABANDONED', job.job_state_details)
dataset/ETHPy150Open duointeractive/media-nommer/media_nommer/feederd/job_cache.py/JobCache.abandon_stale_jobs/original