Amp-Client

 view release on metacpan or  search on metacpan

lib/Amp/DbPoolClient.pm  view on Meta::CPAN

    elsif ($client->responseCode() == 500 && $retryIfNeeded) {
        if ($client->responseContent() =~ m/Server closed connection without sending any data back/) {
            return $warning->();
        }
        elsif ($client->responseContent() =~ m/Transaction Error:/) {
            return $warning->();
        }
        else {
            $self->retriesAttempted($attempts + 1);
            print STDERR "Retrying query to " . $self->host . $self->url . " in 1 second\n";
            sleep 1;
            return $self->__sendRequest();
        }
    }
    else {
        return $warning->();
    }
    $self->retriesAttempted(0);
    return $data;
}

sub addSql {
    my $self = shift;
    my $sql = shift;
    $self->payload->{sql} = $sql;
}

sub addParam {
    my $self = shift;
    my $param = shift;
    push(@{$self->payload->{params}}, $param)
}

sub addOnUpdate {
    my $self = shift;
    my $key = shift;
    my $value = shift;
    $self->payload->{onUpdate}->{$key} = $value;
}

sub quote {
    my $self = shift;
    my $param = shift;

    return Amp::Util::Strings->quote($param);
}

sub ping {
    my $self = shift;

    # nothing to do here since an existing connection is used
    return 1;
}

sub client {
    my $self = shift;
    # Check to see if an instance name was provided and setup the host/url
    $self->checkForRemotePoolConnection();
    # Setup the pool client
    my $client = REST::Client->new();
    $client->setTimeout($self->timeout);
    $client->addHeader('AMP-API-KEY', $self->config->key);
    $client->setHost($self->host);

    return $client;
}

sub checkForRemotePoolConnection {
    my $self = shift;
    if ($self->instanceName()) {
        # If not found by instance name, try the name field which is sometimes different
        my $address = $self->config->getEnv($self->instanceName);
        $self->host($address);
        $self->url('/db-pool-svc');
    }
    elsif ($self->host) {
        $self->url('/db-pool-svc');
    }
    else {
        # Query to the local host at specific port. This query will work on non-apache hosts running the
        # dbpool server
        $self->host('http://0.0.0.0:9395');
        $self->url('/');
    }
}

1;



( run in 0.811 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )