slimta.relay.pool

class slimta.relay.pool.RelayPool([pool_size=None])

Bases: slimta.relay.Relay

Base class that inherits Relay to add the ability to create bounded, cached pools of outbound clients. It maintains a queue of messages to be delivered such that idle clients in the pool pick them up.

Parameters:pool_size – At most this many simultaneous connections will be open to a destination. If this limit is reached and no connections are idle, new attempts will block.
queue = None

This attribute holds the queue object for providing delivery requests to idle clients in the pool.

kill()

This method is used by Relay and Relay-like objects to properly end associated services (such as running Greenlet threads) and close resources.

add_client()

Sub-classes must override this method to create and return a new RelayPoolClient object that will poll for delivery requests.

Return type:RelayPoolClient
attempt(envelope, attempts)

This method must be overridden by sub-classes in order to be passed in to the Queue constructor.

The result of a successful relay attempt is either None or a Reply object. The result of a failing relay attempt is either a PermanentRelayFailure or TransientRelayFailure error.

If the result applies to the entire envelope and all its recipients, implementations may return the successful result or raise the failure. If the result is different per-recipient, then implementations may return a dictionary where the key is a recipient from recipients and the value is the relay result (successful or failing).

Parameters:
  • envelopeEnvelope to attempt delivery for.
  • attempts – Number of times the envelope has attempted delivery.
Returns:

The relay result, as described above.

Raises:

PermanentRelayError, TransientRelayError

class slimta.relay.pool.RelayPoolClient(queue[, idle_timeout=None])

Bases: gevent._greenlet.Greenlet

Base class for implementing clients for handling delivery requests in a RelayPool.

Parameters:
  • queue – The queue on which delivery requests will be received.
  • idle_timeout – If the client can handle multiple, pipelined delivery requests, this is the timeout in seconds that a client will wait for subsequent requests.
idle_timeout = None

This attribute holds the idle timeout for handling multiple delivery requests on the client.

poll()

This method can be used by clients to receive new delivery requests from the client pool. This method will block until a delivery request is received.

Returns:A tuple containing the AsyncResult and the Envelope that make up a delivery request. If no delivery requests are received before the idle_timeout timeout, (None, None) is returned.
_run()

This method must be overridden by sub-classes to handle processing of delivery requests. It should call poll() when it is ready for new delivery requests. The result of the delivery attempt should be written to the AsyncResult object provided in the request.