
lall
Novice
Feb 24, 2009, 2:18 AM
Post #4 of 9
(13438 views)
|
Re: [FishMonger] Extended attibutes inconsistent error
[In reply to]
|
Can't Post
|
|
code for your reference: use DBI; use Win32; use Win32::Process; # ----------------------------- # Include standard subroutines # ----------------------------- ************** # ---------------------------------------------------------------------- # Get Command-Line Parameters: Process ID, Sleep time and Program Name # ---------------------------------------------------------------------- $prcs_cd = $ARGV[0]; $sleeptime = $ARGV[1]; $pgm_nm = $ARGV[2]; # --------------------- # Initialize Variables # --------------------- $log_file = $QMR_PR_LOG_DIR . $pgm_nm . ".log"; $cmd_line = "perl " . $QMR_PR_BIN_DIR . $pgm_nm . " " . $prcs_cd; $me_cmd_line= "perl " . $QMR_PR_BIN_DIR . "qm_pr_process.plx " . $prcs_cd . " " . $sleeptime . " " . $pgm_nm; # -------------------------------- # Connect to the Staging Database # -------------------------------- UDF_connect_STAGING(); # --------------------------- # Prepare all SQL Statements # --------------------------- # Get Requested Status $sthGET = $dbh->prepare( "select rqst_stts_cd, crnt_stts_cd from qmown.t_rpt_prcs where prcs_cd = ?"); if ($DBI::errstr) { UDF_die(6,"sthGET Prepare failed"); } # Update Current Status $sthUPD = $dbh->prepare( "update qmown.t_rpt_prcs set crnt_stts_cd = ?, rec_updt_uid = 'QMBATCH', rec_updt_dt = sysdate, rec_updt_pgm_id = ? where prcs_cd = ?"); if ($DBI::errstr) { UDF_die(6,"sthUPD Prepare failed"); } # Find out if it has been at least 60 minutes since the # process last logged an "active" message. $sthGETtime = $dbh->prepare( "select decode(sign((sysdate - (prcs_msg_dt + 60/1440))),1,'yes','no') from qmown.t_rpt_prcs_log where prcs_log_id in (select max(prcs_log_id) from qmown.t_rpt_prcs_log where prcs_cd = ? and prcs_msg_id = 4)"); if ($DBI::errstr) { UDF_die(6,"sthGETtime Prepare failed"); } # -------------------------------------------------------- # Post an "active" message to the log every 60 minutes. # -------------------------------------------------------- $sthGETtime->execute($prcs_cd); if ($DBI::errstr) { UDF_die(7,"sthGETtime Execute failed"); } $check = $sthGETtime->fetchrow_array(); if ($sthGETtime->rows == 0) { $check = 'yes'; } if ($check eq 'yes') { UDF_Logger($prcs_cd,4,$null); $dbh->commit; } # ---------------------------------------------- # Get the Requested Status Code for the Process # ---------------------------------------------- $sthGET->execute($prcs_cd); if ($DBI::errstr) { UDF_die(7,"sthGET Execute failed"); } else { @data = $sthGET->fetchrow_array(); $rqst_stts_cd = @data[0]; $crnt_stts_cd = @data[1]; } if ($rqst_stts_cd ne $crnt_stts_cd) { # ------------------------------------------------------------ # Update the Current Status Code to the Requested Status Code. # ------------------------------------------------------------ $sthUPD->execute($rqst_stts_cd, $pgm_nm, $prcs_cd); if ($DBI::errstr) { UDF_die(7,"sthUPD Execute failed"); } else { $prcs_msg_data = "From: " . $crnt_stts_cd . " To: " . $rqst_stts_cd; UDF_Logger($prcs_cd,8,$prcs_msg_data); $dbh->commit; $crnt_stts_cd = $rqst_stts_cd; } } # -------------------------------------------------- # If the Process is in Active status, then spawn # and WAIT for specified Process to complete. # -------------------------------------------------- if ($crnt_stts_cd eq 'A') { $i = Win32::Process::Create($PObj, $QMR_PERL_EXE,$cmd_line,0, $Win32::Process::DETACHED_PROCESS + $Win32::Process::CREATE_NO_WINDOW,"."); if (!$i) { UDF_die(5,$pgm_nm . " " . Win32::FormatMessage( Win32::GetLastError())); } else { $pid = $PObj->GetProcessID(); $PObj->Wait(INFINITE); $PObj->GetExitCode($ExitCode); if ($ExitCode != 0) { $prcs_msg_data = $pgm_nm . " rc= " . $ExitCode . " " . Win32::FormatMessage($ExitCode); UDF_Logger($prcs_cd,3,$prcs_msg_data); $dbh->commit; } } } # End of Spawning process. # ---------------------------------------------------- # Spawn another generation of this process controller # ---------------------------------------------------- UDF_reproduce(); # ------------------- # Close this process # ------------------- #$sthLOG->finish; $sthGETtime->finish; $sthGET->finish; $sthUPD->finish; $dbh->disconnect; # ------------------ # Local Subroutines # ------------------ sub UDF_die { UDF_reproduce(); # Reproduce before dying UDF_Logger($prcs_cd,$_[0],$_[1] . " " . $DBI::errstr); # Try to log the error $sthLOG->finish; $sthGET->finish; $sthUPD->finish; $dbh->disconnect; die; } sub UDF_reproduce { # ---------------------------------------------------------------- # If the current status is Active or Dormant, then spawn # another instance of this process after sleeping for the # specified time and shut the current one down. otherwise, # just shut down. # ---------------------------------------------------------------- if ($crnt_stts_cd ne 'K') { sleep($sleeptime); $i = Win32::Process::Create($PObj,$QMR_PERL_EXE,$me_cmd_line,0, $Win32::Process::DETACHED_PROCESS + $Win32::Process::CREATE_NO_WINDOW,"."); if (!$i) { UDF_die(5,'qm_pr_process.plx ' . Win32::FormatMessage( Win32::GetLastError())); } } } exit;
|