
thekidzkid
New User
Oct 24, 2011, 4:56 PM
Post #1 of 3
(605 views)
|
Script OCCASIONALLY Dies During Processing Orders
|
Can't Post
|
|
Hey all- I'm at my wit's end with this program. It seems to work just fine with the exception of an occasional mishap (meaning it seemingly randomly decides to skip 2-3 orders). The behavior is the same on two completely different servers; one being an outdated IBM and the other a new 12-core HP Proliant DL360-G7 with 24GB of RAM. The code is supposed to extract waiting orders from the DB, dump the order to a file, and then transmit the file to another server, via FTP, for processing. For this example, 3 orders came into the database and were processed at the same time: ord_28875, ord_28876, and ord_28877. Only ord_28875 made it to the order-entry server. Logs on the order-entry server died out at about 1% completion, yet the order was still fully placed (makes no sense why logging died out, yet the program completed execution). Please find the included program and minimal logging output below. Any advice would be appreciated. --Thanks Joe ============= Code (DB Server) ============== #!/usr/bin/perl strict; $myPath = "/home/o_writer/tmp/"; use DBI; use Net::FTP; processAllOrders(); sub processAllOrders() { my $dbC = DBI->connect( "dbi:mysql:odb", "db_update", '' ) or die( "Couldn't connect to the database." ); my $ordQ = $dbC->prepare( "SELECT ord_num FROM u_order_defs WHERE ord_ready_to_process = 1;" ); $ordQ->execute; # my $dispT = $dbC->prepare( "UPDATE u_order_defs SET ord_is_processing = 1, ord_ready_to_process = 0 WHERE ord_ready_to_process = 1;" ); # $dispT->execute; while ( @ordLine = $ordQ->fetchrow_array ) { processOrder( $ordLine[ 0 ] ); } my $dispT = $dbC->prepare( "UPDATE u_order_defs SET ord_is_processing = 1, ord_ready_to_process = 0 WHERE ord_ready_to_process = 1;" ); $dispT->execute; } sub processOrder ( $ ) { my $orderNumber = shift; $dbh = DBI->connect( "dbi:mysql:odb", "db_update", '' ) or die( "Couldn't connect to the database." ); $myQ = $dbh->prepare( "SELECT ord_num, rep_id, cust_num, ord_instructions, ord_pick_inst FROM u_order_defs WHERE ord_num = $orderNumber ;"); $myQ->execute; @row = $myQ->fetchrow_array; my $fileName = "ord_" . $orderNumber; print "Opening $fileName \n"; open ( OUTFILE, "> " . $myPath . $fileName ) or die "Cannot open output file."; print OUTFILE $row[ 0 ], "\n"; print OUTFILE $row[ 1 ], "\n"; print OUTFILE $row[ 2 ], "\n"; print OUTFILE $row[ 3 ], "\n"; print OUTFILE $row[ 4 ], "\n"; $myLines = $dbh->prepare( "SELECT line_quantity, line_qflag, prod_num, prod_unitprice, line_piece FROM u_order_lines WHERE ord_num = $orderNumber ;" ); $myLines->execute; while( @oLine = $myLines->fetchrow_array ) { print OUTFILE $oLine[ 2 ], ",", $oLine[ 1 ], ",", $oLine[ 0 ], ",", $oLine[ 3 ], ",", $oLine[ 4 ], "\n"; } close OUTFILE; sendFile( $fileName ); } sub sendFile( $ ) { my $fileName = shift; $ftp = Net::FTP->new( "192.1.1.12" ); $ftp->login( "r_order", 'password' ); $ftp->cwd( "/temp/u_orders/" ),"\n"; $ftp->put( $myPath . $fileName, $fileName ); $ftp->quit; unlink $myPath . $fileName; } =============== Log Output (DB Server) =============== What Happened to ord_28876 and ord_28877??? Also, the server processing ord_28875 screwed up while processing the order. The order looks normal in vim. Were hidden characters inserted into ord_28875 which then broke order-entry on the other server? Opening ord_28870 Opening ord_28871 Opening ord_28872 Opening ord_28873 Opening ord_28874 Opening ord_28875 Opening ord_28878 Opening ord_28879 Opening ord_28880 Opening ord_28881 Opening ord_28882 =============== Log Output (Order-Entry Server) =============== 24-Oct-11 16:25.02:--> Processing File: ord_28875 24-Oct-11 16:25.02:--> Transferring CONTROL To ORD_PARSE_TEXT_FILE From ORD_PROCESS_ALL_ORDERS 24-Oct-11 16:25.02:--> CONTROL Was Successfully Transferred to ORD_PARSE_TEXT_FILE 24-Oct-11 16:25.02:--> Extracted Line 1: Internal Order Number > 28875 24-Oct-11 16:25.02:--> Extracted Line 2: Agent/Clerk/Salesman ID Number > 14 24-Oct-11 16:25.02:--> Extracted Line 3: Customer Number > 0037330 24-Oct-11 16:25.02:--> Extracted Line 4: Invoice Instructions > 24-Oct-11 16:25.02:--> Extracted Line 5: Pick Ticket Instructions > 24-Oct-11 16:25.02:--> Transferring CONTROL To ORD_INIT_ORDER From ORD_PARSE_TEXT_FILE 24-Oct-11 16:25.02:--> CONTROL Was Successfully Transferred To ORD_INIT_ORDER 24-Oct-11 16:25.02:--> The Following Values Were Passed From the Calling Application: 24-Oct-11 16:25.02:--> Customer Number: 0037330 24-Oct-11 16:25.02:--> Clerk Number: 14 24-Oct-11 16:25.02:--> Invoice Instructions: 24-Oct-11 16:25.02:--> Pick Ticket Instructions: The logging then died and picked up again at 16:26 with ord_28878, however, ord_28875 was still successfully placed.
|