mISDN and perl astcc agi

He mate,

I search from log time how to make call faster with mISDN
I use the astcc-agi to call and all is ok if there is few calls and first channels are free but when call have to use last channel from database its very long, I’m not expert with perl but I think if I can try and take random channels with the code it could solve the problem
I have make my DB with mISDN1, mISDN2, mISDN3…
Here is the code
########FIRST it select and store data for a dialsting includig path

sub getphone() {
my ($number) = @_;
my $sth = $dbh->prepare(“SELECT * FROM routes WHERE " . $dbh->quote($number) . " RLIKE concat(’^’, pattern) ORDER BY LENGTH(pattern) DESC”);
$sth->execute;
$res = $sth->fetchrow_hashref;
$sth->finish;
return $res;
}

##########HERE it look on database for trunk information

sub trytrunk() {
my ($trunk, $phone, $maxtime) = @_;
my $sth;
my $res;
my $dialstr;
$sth = $dbh->prepare(“SELECT * FROM trunks WHERE name=” . $dbh->quote($trunk));
$sth->execute;
$res = $sth->fetchrow_hashref;
$sth->finish;
return “CHANUNAVAIL” unless $res;

###########HERE is the dial $res->{path} have informations mISDN1:mISDN2…

if ($res->{tech} eq “mISDN”) {
$dialstr = “mISDN/$res->{path}/$phone|90|HL(” . ($maxtime * 60 * 1000) . “:30000:30000)”;
$res = $AGI->exec(“DIAL $dialstr”);

I would like to have $res->{path} with random order mISDN3:mISDN1…
when I dial :frowning:

If any perl expert here thank’s in advance !

No perl expert here !!!

After many hours I have found a working solution

On Top Astcc-agi add

use List::Util ‘shuffle’;
@shuffled = shuffle(@list);

and change this near the end

just change this var
my @trunks = split(/:/, $numdata->{trunks});
for
my @trunks = shuffle(split(/:/, $numdata->{trunks}));

Now AGI take ISDN channels in random order each call :smile:

You could try:
In DB mark channel which is used, and then unmark.
Make a group and dial group.

Thanks Bira more
I have already long time ago to call with a group on astcc
it don’t work fine and use only the first Channel.

for the set inuse yes it’s a good idea surely the best way and exactly what I’ll do on next dev but I must make long test for this feature to be sure that the channel will each time set free on hangup.
You can imagine what will hapen in case of script failure :frowning:

Yes I can imagine - I saw it couple of times.
I could “propose” 3 approaches if you dial from AGI:
in AGI script (if written in Perl) - you should put something like:

$SIG{HUP} = sub { #clean what should be cleaned if hangup exit(0); };
Or run script as dead agi - which is not recommended.
Or clean everything from h extension.