def test_get_pending_jobs_info(pending_jobs, skip_if_state, max_slots, expected_filtered_jobs, mocker): mock = mocker.patch("common.schedulers.sge_commands.get_jobs_info", return_value=pending_jobs, autospec=True) assert_that(get_pending_jobs_info( max_slots, skip_if_state)).is_equal_to(expected_filtered_jobs) mock.assert_called_with(job_state_filter="p")
def _get_required_slots(instance_properties, max_size): """Compute the total number of slots required by pending jobs.""" max_cluster_slots = max_size * instance_properties.get("slots") pending_jobs = get_pending_jobs_info(max_slots_filter=max_cluster_slots, skip_if_state=SGE_HOLD_STATE) slots = 0 for job in pending_jobs: slots += job.slots return slots
def hasPendingJobs(instance_properties, max_size): try: max_cluster_slots = max_size * instance_properties.get("slots") pending_jobs = get_pending_jobs_info( max_slots_filter=max_cluster_slots, skip_if_state=SGE_HOLD_STATE) return len(pending_jobs) > 0, False except Exception as e: log.error( "Failed when checking for pending jobs with exception %s. Reporting no pending jobs.", e) return False, True
def has_pending_jobs(instance_properties, max_size): """ Check if there is any pending job in the queue. :return: a pair (has_pending_job, has_error) where has_error communicates if there was an error when checking for pending jobs. """ try: max_cluster_slots = max_size * instance_properties.get("slots") pending_jobs = get_pending_jobs_info(max_slots_filter=max_cluster_slots, skip_if_state=SGE_HOLD_STATE) logging.info("Found the following pending jobs:\n%s", pending_jobs) return len(pending_jobs) > 0, False except Exception as e: log.error("Failed when checking for pending jobs with exception %s. Reporting no pending jobs.", e) return False, True