def METHOD_NAME():
    """Main Foreman thread that helps manage the Batch job queue.
    Will find jobs that failed, hung, or got lost and requeue them.
    Also will queue up Janitor jobs regularly to free up disk space.
    It does so on a loop forever that won't spin faster than
    MIN_LOOP_TIME, but it may spin slower than that.
    """
    # last_janitorial_time = timezone.now()
    last_dbclean_time = timezone.now()
    while True:
        # Perform two heartbeats, one for the logs and one for Monit:
        logger.info("The Foreman's heart is beating, but he does not feel.")
        # Write the health file for Monit to check
        now_secs = int(time.time())
        with open("/tmp/foreman_last_time", "w") as timefile:
            timefile.write(str(now_secs))
        start_time = timezone.now()
        # Requeue jobs of each failure class for each job type.
        # The order of processor -> downloader -> surveyor is intentional.
        # Processors go first so we process data sitting on disk.
        # Downloaders go first so we actually queue up the jobs in the database.
        # Surveyors go last so we don't end up with tons and tons of unqueued jobs.
        requeuing_functions_in_order = [
            retry_failed_processor_jobs,
            retry_hung_processor_jobs,
            retry_lost_processor_jobs,
            retry_unqueued_processor_jobs,
            retry_failed_downloader_jobs,
            retry_hung_downloader_jobs,
            retry_lost_downloader_jobs,
            retry_unqueued_downloader_jobs,
            retry_failed_survey_jobs,
            retry_hung_survey_jobs,
            retry_lost_survey_jobs,
            retry_unqueued_survey_jobs,
        ]
        for function in requeuing_functions_in_order:
            try:
                function()
            except Exception:
                logger.exception("Caught exception in %s: ", function.__name__)
        if settings.RUNNING_IN_CLOUD:
            # Disable this for now because this will trigger regardless of
            # whether or not we have an instance to clean up, which means that
            # we could spin up an instance just to run a janitor job.
            # if timezone.now() - last_janitorial_time > JANITOR_DISPATCH_TIME:
            #     send_janitor_jobs()
            #     last_janitorial_time = timezone.now()
            if timezone.now() - last_dbclean_time > DBCLEAN_TIME:
                clean_database()
                last_dbclean_time = timezone.now()
        loop_time = timezone.now() - start_time
        if loop_time < MIN_LOOP_TIME:
            remaining_time = MIN_LOOP_TIME - loop_time
            if remaining_time.seconds > 0:
                time.sleep(remaining_time.seconds)