Added Validate XFER vicidial_auto_calls: "--check-xfers" flag to the flush DB queue script
git-svn-id: svn://192.168.202.10@3849 3d104415-ff17-0410-8863-d5cf3c621b8a
This commit is contained in:
@@ -35,6 +35,7 @@
|
|||||||
# 231118-1256 - Added clearing of old vicidial_3way_press_live records
|
# 231118-1256 - Added clearing of old vicidial_3way_press_live records
|
||||||
# 231228-1901 - Added optimizing of vicidial_3way_press_multi records
|
# 231228-1901 - Added optimizing of vicidial_3way_press_multi records
|
||||||
# 240219-0811 - Added optimizing of server_live_... tables
|
# 240219-0811 - Added optimizing of server_live_... tables
|
||||||
|
# 240709-1300 - Added Validate XFER vicidial_auto_calls: "--check-xfers" flag
|
||||||
#
|
#
|
||||||
|
|
||||||
$session_flush=0;
|
$session_flush=0;
|
||||||
@@ -42,6 +43,7 @@ $SSsip_event_logging=0;
|
|||||||
$reset_stuck_leads=0;
|
$reset_stuck_leads=0;
|
||||||
$stuck_lists='';
|
$stuck_lists='';
|
||||||
$stuck_listsSQL='';
|
$stuck_listsSQL='';
|
||||||
|
$check_xfers=0;
|
||||||
|
|
||||||
### begin parsing run-time options ###
|
### begin parsing run-time options ###
|
||||||
if (length($ARGV[0])>1)
|
if (length($ARGV[0])>1)
|
||||||
@@ -64,6 +66,7 @@ if (length($ARGV[0])>1)
|
|||||||
print " [--session-flush] = flush the vicidial_sessions_recent table\n";
|
print " [--session-flush] = flush the vicidial_sessions_recent table\n";
|
||||||
print " [--reset-stuck-leads] = reset status of ERI/INCALL leads to NEW if previewed but not called\n";
|
print " [--reset-stuck-leads] = reset status of ERI/INCALL leads to NEW if previewed but not called\n";
|
||||||
print " [--stuck-lists=X] = restrict stuck leads check to these lists: X-Y-Z multiple lists separated by a single dash\n";
|
print " [--stuck-lists=X] = restrict stuck leads check to these lists: X-Y-Z multiple lists separated by a single dash\n";
|
||||||
|
print " [--check-xfers] = validates that XFER status vicidial_auto_calls records are live, if not, they are deleted\n";
|
||||||
print "\n";
|
print "\n";
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
@@ -101,6 +104,12 @@ if (length($ARGV[0])>1)
|
|||||||
if ($Q < 1)
|
if ($Q < 1)
|
||||||
{print "\n----- RESET STUCK LEADS ----- $reset_stuck_leads \n\n";}
|
{print "\n----- RESET STUCK LEADS ----- $reset_stuck_leads \n\n";}
|
||||||
}
|
}
|
||||||
|
if ($args =~ /--check-xfers/i)
|
||||||
|
{
|
||||||
|
$check_xfers=1;
|
||||||
|
if ($Q < 1)
|
||||||
|
{print "\n----- CHECK XFERS ----- $check_xfers \n\n";}
|
||||||
|
}
|
||||||
if ($args =~ /--stuck-lists=/i)
|
if ($args =~ /--stuck-lists=/i)
|
||||||
{
|
{
|
||||||
@data_in = split(/--stuck-lists=/,$args);
|
@data_in = split(/--stuck-lists=/,$args);
|
||||||
@@ -734,7 +743,6 @@ if ($session_flush > 0)
|
|||||||
}
|
}
|
||||||
if (!$Q) {print " - OPTIMIZE vicidial_sessions_recent \n";}
|
if (!$Q) {print " - OPTIMIZE vicidial_sessions_recent \n";}
|
||||||
}
|
}
|
||||||
$dbhA->disconnect();
|
|
||||||
|
|
||||||
|
|
||||||
if ($reset_stuck_leads > 0)
|
if ($reset_stuck_leads > 0)
|
||||||
@@ -878,6 +886,122 @@ if ($reset_stuck_leads > 0)
|
|||||||
|
|
||||||
if (!$Q) {print " - STUCK leads check finished, stuck calls checked: $a reset: $found_stuck_ct, exiting...\n";}
|
if (!$Q) {print " - STUCK leads check finished, stuck calls checked: $a reset: $found_stuck_ct, exiting...\n";}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($check_xfers > 0)
|
||||||
|
{
|
||||||
|
$xfers_sc_ct=0;
|
||||||
|
$killed_xfers_ct=0;
|
||||||
|
# Gather all XFER vicidial_auto_calls records older than X seconds
|
||||||
|
$stmtA = "SELECT auto_call_id,server_ip,lead_id,callerid,channel,call_time FROM vicidial_auto_calls where status IN('XFER') and call_time <= \"$SQLdate_NEG_1hour\" order by call_time limit 10000;";
|
||||||
|
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||||
|
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||||
|
$sthArowsXFERS=$sthA->rows;
|
||||||
|
if ($DBX) {print "DEBUG: $sthArowsXFERS|$stmtA|\n";}
|
||||||
|
$a=0;
|
||||||
|
while ($sthArowsXFERS > $a)
|
||||||
|
{
|
||||||
|
@aryA = $sthA->fetchrow_array;
|
||||||
|
$ST_auto_call_id[$a] = $aryA[0];
|
||||||
|
$ST_server_ip[$a] = $aryA[1];
|
||||||
|
$ST_lead_id[$a] = $aryA[2];
|
||||||
|
$ST_callerid[$a] = $aryA[3];
|
||||||
|
$ST_channel[$a] = $aryA[4];
|
||||||
|
$ST_call_date[$a] = $aryA[5];
|
||||||
|
$a++;
|
||||||
|
}
|
||||||
|
$sthA->finish();
|
||||||
|
|
||||||
|
$a=0;
|
||||||
|
while ($sthArowsXFERS > $a)
|
||||||
|
{
|
||||||
|
$active_count=0;
|
||||||
|
$channelSQL='';
|
||||||
|
if (length($ST_channel[$a]) > 0) {$channelSQL="or channel='$ST_channel[$a]'";}
|
||||||
|
$stmtA = "SELECT count(*) FROM live_channels where channel_group='$ST_callerid[$a]' $channelSQL;";
|
||||||
|
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||||
|
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||||
|
$sthArowsACTIVE=$sthA->rows;
|
||||||
|
if ($DBX) {print "DEBUG: $sthArowsACTIVE|$stmtA|\n";}
|
||||||
|
if ($sthArowsACTIVE > 0)
|
||||||
|
{
|
||||||
|
@aryA = $sthA->fetchrow_array;
|
||||||
|
$active_count = $aryA[0];
|
||||||
|
}
|
||||||
|
$sthA->finish();
|
||||||
|
|
||||||
|
if ($active_count > 0)
|
||||||
|
{if($DB){print STDERR "Call active: $active_count|$ST_lead_id[$a]|$ST_callerid[$a]|$ST_server_ip[$a]|$ST_channel[$a]|$ST_call_date[$a]|\n";}}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if($DB){print STDERR "Xfer fail 1st check: $active_count|$ST_lead_id[$a]|$ST_callerid[$a]|$ST_server_ip[$a]|$ST_channel[$a]|$ST_call_date[$a]|\n";}
|
||||||
|
|
||||||
|
$TK_auto_call_id[$xfers_sc_ct] = $ST_auto_call_id[$a];
|
||||||
|
$TK_server_ip[$xfers_sc_ct] = $ST_server_ip[$a];
|
||||||
|
$TK_lead_id[$xfers_sc_ct] = $ST_lead_id[$a];
|
||||||
|
$TK_callerid[$xfers_sc_ct] = $ST_callerid[$a];
|
||||||
|
$TK_channel[$xfers_sc_ct] = $ST_channel[$a];
|
||||||
|
$TK_call_date[$xfers_sc_ct] = $ST_call_date[$a];
|
||||||
|
|
||||||
|
$xfers_sc_ct++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$a++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($xfers_sc_ct > 0)
|
||||||
|
{
|
||||||
|
if($DB){print STDERR "Xfers dead found($a), waiting 5 seconds before 2nd round check...\n";}
|
||||||
|
# sleep for 5 seconds, then check the dead xfers flagged in the first round of checking
|
||||||
|
sleep(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
$a=0;
|
||||||
|
while ($xfers_sc_ct > $a)
|
||||||
|
{
|
||||||
|
$active_count=0;
|
||||||
|
|
||||||
|
$channelSQL='';
|
||||||
|
if (length($TK_channel[$a]) > 0) {$channelSQL="or channel='$TK_channel[$a]'";}
|
||||||
|
$stmtA = "SELECT count(*) FROM live_channels where channel_group='$TK_callerid[$a]' $channelSQL;";
|
||||||
|
$sthA = $dbhA->prepare($stmtA) or die "preparing: ",$dbhA->errstr;
|
||||||
|
$sthA->execute or die "executing: $stmtA ", $dbhA->errstr;
|
||||||
|
$sthArowsACTIVE=$sthA->rows;
|
||||||
|
if ($DBX) {print "DEBUG: $sthArowsACTIVE|$stmtA|\n";}
|
||||||
|
if ($sthArowsACTIVE > 0)
|
||||||
|
{
|
||||||
|
@aryA = $sthA->fetchrow_array;
|
||||||
|
$active_count = $aryA[0];
|
||||||
|
}
|
||||||
|
$sthA->finish();
|
||||||
|
|
||||||
|
if ($active_count > 0)
|
||||||
|
{if($DB){print STDERR "Call active 2nd check: $active_count|$TK_lead_id[$a]|$TK_callerid[$a]|$TK_server_ip[$a]|$TK_channel[$a]|$TK_call_date[$a]|\n";}}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!$Q) {print " - dead xfer found: $active_count|$TK_lead_id[$a]|$TK_callerid[$a]|$TK_server_ip[$a]|$TK_channel[$a]|$TK_call_date[$a]|\n";}
|
||||||
|
|
||||||
|
# delete vicidial_auto_calls record
|
||||||
|
$stmtA = "DELETE FROM vicidial_auto_calls WHERE auto_call_id='$TK_auto_call_id[$a]';";
|
||||||
|
if($DB){print STDERR "\n|$stmtA|\n";}
|
||||||
|
if (!$T) {$affected_rows = $dbhA->do($stmtA);}
|
||||||
|
if ($DBX) {print "DEBUG: $affected_rows|$stmtA|\n";}
|
||||||
|
$killed_xfers_ct++;
|
||||||
|
if (!$Q) {print " - dead xfer call has been deleted from vac: $TK_auto_call_id[$a]|$killed_xfers_ct|\n";}
|
||||||
|
|
||||||
|
if (!$XFERLOGfile) {$XFERLOGfile = "$PATHlogs/killed_xfers.$year-$mon-$mday";}
|
||||||
|
open(Xout, ">>$XFERLOGfile")
|
||||||
|
|| die "Can't open $XFERLOGfile: $!\n";
|
||||||
|
print Xout "$SQLdate_NOW|$affected_rows|$TK_auto_call_id[$a]|$TK_lead_id[$a]|$TK_callerid[$a]|$TK_server_ip[$a]|$TK_channel[$a]|$TK_call_date[$a]|\n";
|
||||||
|
close(Xout);
|
||||||
|
}
|
||||||
|
$a++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$Q) {print " - XFER leads check finished, stuck calls checked: $sthArowsXFERS deleted: $killed_xfers_ct, exiting...\n";}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$dbhA->disconnect();
|
$dbhA->disconnect();
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
|
|||||||
Reference in New Issue
Block a user