pynenc.broker.mem_broker#

Module Contents#

Classes#

MemBroker

An in-memory implementation of the BaseBroker.

API#

class pynenc.broker.mem_broker.MemBroker(app: pynenc.app.Pynenc)[source]#

Bases: pynenc.broker.base_broker.BaseBroker

An in-memory implementation of the BaseBroker.

This subclass of BaseBroker implements the abstract methods for routing, retrieving, and purging invocations using an in-memory deque. It’s primarily intended for testing and demonstration purposes.

Warning

The MemBroker class generates the queue in the process’s memory and is not suitable for production systems. Its use should be limited to testing or demonstration purposes only.

Parameters:

app (Pynenc) – A reference to the Pynenc application.

Initialization

route_invocation(invocation: pynenc.invocation.dist_invocation.DistributedInvocation) None[source]#

Route an invocation by adding it to the in-memory queue.

This method serializes the DistributedInvocation object to JSON and appends it to the deque, effectively queuing it for processing.

Parameters:

invocation (DistributedInvocation) – The invocation to be queued.

retrieve_invocation() Optional[pynenc.invocation.dist_invocation.DistributedInvocation][source]#

Retrieve the next invocation from the queue.

This method pops the next item from the deque, deserializes it from JSON, and returns the DistributedInvocation object. If the queue is empty, it returns None.

Returns:

The next invocation from the queue, or None if the queue is empty.

purge() None[source]#

Clear all invocations from the in-memory queue.

This method empties the deque, removing all pending invocations.