END_TEST START_TEST(count_jobs_submitted_test) { unsigned int submitted; job pjob; memset(&pjob, 0, sizeof(pjob)); users.lock(); users.clear(); users.unlock(); submitted = count_jobs_submitted(&pjob); fail_unless(submitted == 1, "incorrect count for non-array job"); pjob.ji_wattr[JOB_ATR_job_array_request].at_val.at_str = (char *)"0-10"; submitted = count_jobs_submitted(&pjob); fail_unless(submitted == 11, "incorrect count for 0-10"); }
int increment_queued_jobs( user_info_holder *uih, char *user_name, job *pjob) { int rc = PBSE_NONE; user_info *ui; int index; unsigned int num_submitted = count_jobs_submitted(pjob); pthread_mutex_lock(uih->ui_mutex); /* get the user if there is one */ if ((index = get_value_hash(uih->ui_ht, user_name)) > 0) { ui = uih->ui_ra->slots[index].item; ui->num_jobs_queued += num_submitted; } else { /* user doesn't exist, create a new one and insert */ ui = calloc(1, sizeof(user_info)); ui->user_name = strdup(user_name); ui->num_jobs_queued = num_submitted; if ((index = insert_thing(uih->ui_ra, ui)) == -1) { rc = ENOMEM; log_err(rc, __func__, (char *)"Can't resize the user info array"); } else { add_hash(uih->ui_ht, index, ui->user_name); } } pthread_mutex_unlock(uih->ui_mutex); return(rc); } /* END increment_queued_jobs() */
int can_queue_new_job( char *user_name, job *pjob) { long max_queuable = -1; int can_queue_another = TRUE; unsigned int num_queued = 0; unsigned int num_to_add; get_svr_attr_l(SRV_ATR_MaxUserQueuable, &max_queuable); if (max_queuable >= 0) { num_to_add = count_jobs_submitted(pjob); num_queued = get_num_queued(&users, user_name); if (num_queued + num_to_add > (unsigned int)max_queuable) can_queue_another = FALSE; } return(can_queue_another); } /* END can_queue_new_job() */