int scheduling_cycle( int sd) { server_info *sinfo; /* ptr to the server/queue/job/node info */ job_info *jinfo; /* ptr to the job to see if it can run */ int ret = SUCCESS; /* return code from is_ok_to_run_job() */ char log_msg[MAX_LOG_SIZE]; /* used to log an message about job */ char comment[MAX_COMMENT_SIZE]; /* used to update comment of job */ sched_log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_REQUEST, "", "Entering Schedule"); update_cycle_status(); /* create the server / queue / job / node structures */ if ((sinfo = query_server(sd)) == NULL) { fprintf(stderr, "Problem with creating server data strucutre\n"); return(0); } if (init_scheduling_cycle(sinfo) == 0) { sched_log( PBSEVENT_DEBUG, PBS_EVENTCLASS_SERVER, sinfo -> name, "init_scheduling_cycle failed."); free_server(sinfo, 1); return(0); } /* main scheduling loop */ while ((jinfo = next_job(sinfo, 0))) { sched_log( PBSEVENT_DEBUG2, PBS_EVENTCLASS_JOB, jinfo->name, "Considering job to run"); if ((ret = is_ok_to_run_job(sd, sinfo, jinfo->queue, jinfo)) == SUCCESS) { run_update_job(sd, sinfo, jinfo->queue, jinfo); } else { if (jinfo->can_never_run) { sched_log( PBSEVENT_JOB, PBS_EVENTCLASS_JOB, jinfo->name, "Job Deleted because it would never run"); pbs_deljob(sd, jinfo->name, "Job could never run"); } jinfo->can_not_run = 1; if (translate_job_fail_code(ret, comment, log_msg)) { /* if the comment doesn't get changed, its because it hasn't changed. * if the reason for the job has not changed, we do not need to log it */ if (update_job_comment(sd, jinfo, comment) == 0) { sched_log( PBSEVENT_SCHED, PBS_EVENTCLASS_JOB, jinfo->name, log_msg); } } if ((ret != NOT_QUEUED) && cstat.strict_fifo) { update_jobs_cant_run( sd, jinfo->queue->jobs, jinfo, COMMENT_STRICT_FIFO, START_AFTER_JOB); } } } if (cstat.fair_share) update_last_running(sinfo); free_server(sinfo, 1); /* free server and queues and jobs */ sched_log(PBSEVENT_DEBUG2, PBS_EVENTCLASS_REQUEST, "", "Leaving schedule\n"); return 0; }
/* CAMqa54502 - pass in currency_struct */ int create_frn_send(CURRENCY_STRUCT *currency_struct) { int status = SUCCESS; int num_trans = 0; int num_closed = 0; Arb_numeric debit_amt = ARB_NUMERIC_ZERO; /* total amount of debits */ Arb_numeric credit_amt = ARB_NUMERIC_ZERO; /* total amount of credits */ Arb_numeric result = ARB_NUMERIC_ZERO; CC_FILE_STATUS frec; char buff1[ARB_NUMERIC_LEN]; char buff2[ARB_NUMERIC_LEN]; int retval; /*DENqa62462, created file type*/ int file_type = FILE_FRN_EFT_OUT; memset(&frec, 0, sizeof(CC_FILE_STATUS)); gFile_id = 0; /*gCycle_id = 0;*/ /* Check for, and reprocess any previous failures; i.e., any ** outgoing French files (file_type == FILE_FRN_EFT_OUT) where the ** file_status is FILE_STAT_INUSE or FILE_STAT_PROC_ERR. Since ** we are just starting, and no other task can be running, ** then anything "INUSE" must be from a previous failure. */ /* BUG: Future version should check for previous CREATE failures here. */ /* Create unique file name for new send file using timestamp */ /* Sets globals gFile_date_time and gFile_name */ create_file_name(); /* Create FILE_STATUS entry, Sets global gFile_id */ if (insert_file_status(&gFile_id, gCycle_id, gFile_name) == FAILURE) { emit(FILE_LINE, EFT_FS_FILE_ERR, gFile_name, gFile_id); gContinue_create = 0; return(CREATE_FILE_FAILURE); } /*****************************/ /* *** BEGIN TRANSACTION *** */ /*****************************/ if (arb_begin_tran(Dbpcust1, (char *) arb_get_process_id()) == FAILURE) { emit(FILE_LINE, EFT_BEGIN_TRAN_ERR, "send file"); arb_cancel(Dbpcust1); rollback_file_status(); return(CREATE_FILE_FAILURE); } if (gBalance_billing == 1) { /* Prepare PAYMENT_TRANS table: create rows with the current profiles */ if (create_trans_current_profile() == FAILURE) { arb_rollback_tran(Dbpcust1, (char *) arb_get_process_id()); rollback_file_status(); emit(FILE_LINE, EFT_CURR_PROF_TRANS); return(CREATE_FILE_FAILURE); } } /* Lock and Count sendable transactions */ if (lock_frn_trans(currency_struct) == FAILURE) { arb_rollback_tran(Dbpcust1, (char *) arb_get_process_id()); rollback_file_status(); emit(FILE_LINE, EFT_LOCK_TRANS); return(CREATE_FILE_FAILURE); } emit(FILE_LINE, EFT_CREATE_SEND, gFile_name, gFile_id, gCycle_id); if (create_cycle_entry(gCH_curr.clearing_house_id, gCycle_id, CYCLE_INUSE) <= 0) { arb_rollback_tran(Dbpcust1, (char *) arb_get_process_id()); rollback_file_status(); emit(FILE_LINE, EFT_CYCLE_CREATE_ERR, gCycle_id); return(CREATE_FILE_FAILURE); } if (arb_commit_tran(Dbpcust1) == FAILURE) /*** COMMIT TRANSACTION ***/ { emit(FILE_LINE, EFT_COMMIT_TRAN_ERR, "send file"); arb_cancel(Dbpcust1); rollback_file_status(); return(CREATE_FILE_FAILURE); } emit(FILE_LINE, EFT_BEGIN_PROCESSING, gTransactions, gFile_id); /* Create file, read TRANS records, write to the file, close file */ /* CAMqa54502 - pass in currency_struct */ if ((retval = create_frn_file(&num_trans, &num_closed, &debit_amt, &credit_amt,currency_struct)) <= 0) { emit(FILE_LINE, EFT_FILE_CREATE_ERR, gFile_id); if (unlock_file_status(Dbpadm, gFile_id, gServer_id, file_type, FILE_STAT_PROC_ERR, 0) != 1) { emit(FILE_LINE, EFT_FS_UPDATE_ERR, gFile_id, FILE_STAT_PROC_ERR); } /* update CYCLE_STATUS */ if (update_cycle_status(gCH_curr.clearing_house_id, gCycle_id, CYCLE_ERROR) <= 0) { emit(FILE_LINE, EFT_CYCLE_ERR, "updating", gCH_curr.clearing_house_id, gCycle_id); } if (manual_rollback_trans(gFile_id) != 1) { /* SERIOUS problem. Cannot unset TRANS entries. They may remain ** marked as "PEN" (pending) and will NOT be sent out to clearing ** house until status is changed. */ emit(FILE_LINE, EFT_ROLLBACK_TRANS, gFile_id); } return(CREATE_FILE_FAILURE); } else if (retval == 2) { if (unlock_file_status(Dbpadm, gFile_id, gServer_id, file_type, FILE_STAT_PROC_ERR, 0) != 1) { emit(FILE_LINE, EFT_FS_UPDATE_ERR, gFile_id, FILE_STAT_NEW); } else if (update_cycle_status(gCH_curr.clearing_house_id, gCycle_id, CYCLE_ERROR) <= 0) { emit(FILE_LINE, EFT_CYCLE_ERR, "updating", gCH_curr.clearing_house_id, gCycle_id); } emit(FILE_LINE, EFT_NO_SEND_FILE); return(CREATE_FILE_NODATA); } /* Successfully created output (send) file. Update file & cycle status. */ status = CREATE_FILE_SUCCESS; arb_num_arith(&result, &debit_amt, ARB_NUM_ADD, &credit_amt); if (unlock_file_status(Dbpadm, gFile_id, gServer_id, file_type, FILE_STAT_NEW, 0) != 1) { emit(FILE_LINE, EFT_FS_UPDATE_ERR, gFile_id, FILE_STAT_NEW); status = CREATE_FILE_FAILURE; } else if (update_cycle(gCH_curr.clearing_house_id, gCycle_id, CYCLE_NEW, CYCLE_NEW_STATS, num_trans - num_closed, &result) <= 0) { /* update of CYCLE_STATUS to NEW failed; try to update status for ** both cycle and file to ERROR. Ignore errors updating since if we ** got here, additional updates will probably fail. */ emit(FILE_LINE, EFT_CYCLE_ERR, "updating new", gCH_curr.clearing_house_id, gCycle_id); status = CREATE_FILE_FAILURE; } if (status == CREATE_FILE_FAILURE) { /* We were doing so well! TRANS entries were successfully locked, ** we successfully created output file. And then at the last step, we get ** an error trying to update the FILE_STATUS and/or CYCLE_STATUS ** entries. Let's try mark the file & cycle to ERROR and attempt to manually ** rollback TRANS changes (i.e., reset the current "PEN" transactions ** back to status = NULL so they can be sent out next time around). ** NOTE: Most likely, the following updates and manual rollback will fail. ** A likely problem to have gotten us here is full transaction log. Manual ** intervention may be required! Don't bother checking return status from ** these updates. */ if (unlock_file_status(Dbpadm, gFile_id, gServer_id, file_type, FILE_STAT_NEW, 0) != 1) { emit(FILE_LINE, EFT_FS_UPDATE_ERR, gFile_id, FILE_STAT_PROC_ERR); } /* update CYCLE_STATUS */ if ((status = update_cycle_status(gCH_curr.clearing_house_id, gCycle_id, CYCLE_ERROR)) <= 0) { emit(FILE_LINE, EFT_CYCLE_ERR, "updating", gCH_curr.clearing_house_id, gCycle_id); } if (manual_rollback_trans(gFile_id) != 1) { emit(FILE_LINE, EFT_ROLLBACK_TRANS, gFile_id); } return(CREATE_FILE_FAILURE); } arb_numeric_to_string(&debit_amt, buff1); arb_numeric_to_string(&credit_amt, buff2); if(!VerifyStringLength(buff1,REPORT_AMOUNT_MAX_LENGTH) || !VerifyStringLength(buff2,REPORT_AMOUNT_MAX_LENGTH)) return (CREATE_FILE_FAILURE); /* CONTROL REPORT */ fprintf(RptFileFD,"\n Send File Name: %s\n", gFile_name); fprintf(RptFileFD," ClearHouse Cycle ID File ID # Trans Debit Amt Credit Amt\n"); fprintf(RptFileFD," %10s %8d %8d %8d %18.18s %18.18s\n", gCH_curr.clearing_house_id, gCycle_id, gFile_id, num_trans - num_closed, buff1, buff2); return(CREATE_FILE_SUCCESS); }