Как обнулять penalty в конце дня, чтобы у всех в начале дня у всех был penalty 0?
Код: Выделить всё
#!/usr/bin/perl
use strict;
use warnings;
use DBI;
use Time::Local;
use POSIX qw(strftime);
use Asterisk::AMI;
# коннектимся к серверу MySql
my $dbh = DBI->connect("DBI:mysql:hostname=hostname;database="dbname","login", 'password db') or die "Check connection settings\n";
my $sth = $dbh->prepare("SET NAMES 'utf8'");
my $res = $sth->execute;
# Выполнить запрос
$sth = $dbh->prepare("
SELECT agent, sum(data2) as sec FROM dbname
where event in ('COMPLETEAGENT', 'COMPLETECALLER')
and created > CURRENT_DATE()
group by agent
order by sec
");
$sth->execute;
my $i=0;
while (my @row = $sth->fetchrow_array()){
my $sip = $row[0];
Penalty($sip,"queueNAME",$i);
Penalty($sip,"queueNAME",$i);
Penalty($sip,"queueNAME",$i);
$i++;
}
sub Penalty{
my ($sip, $queue, $penalty) = @_;
my $astman = Asterisk::AMI->new(PeerAddr => 'hostname',
PeerPort => '5038',
Username => 'loginAMI',
Secret => 'passwordAMI',
Events => 'on'
);
die "Unable to connect to asterisk" unless ($astman);
my $response = $astman->action({ Action => 'QueuePenalty',
ActionID => 1234,
Interface => $sip,
Penalty => $penalty,
Queue => $queue
});
}
my $rc = $dbh->disconnect;
1;