wcraas_common package

Submodules

wcraas_common.config module

class wcraas_common.config.AMQPConfig[source]

Bases: wcraas_common.config.AMQPConfig

classmethod fromenv()[source]

Create a wcraas_common.AMQPConfig from Environment Variables.

>>> conf = AMQPConfig.fromenv()
>>> type(conf)
<class 'wcraas_common.config.AMQPConfig'>
>>> conf._fields
('host', 'port', 'user', 'password')
>>> conf.host
'localhost'
>>> conf.port
5672
>>> conf.user
'guest'
>>> conf.password
'guest'

wcraas_common.wcraas_common module

The WCraaS Common module aims to single-source reused code across WCraaS the platform.

class wcraas_common.wcraas_common.WcraasWorker(amqp: wcraas_common.config.AMQPConfig, loglevel: int, *args, **kwargs)[source]

Bases: abc.ABC

Base class for WCraaS Worker classes, aiming to single-source AMQP boilerplate.

amqp
create_channel_pool(pool_size: int = 2, channel_size: int = 10) → aio_pika.pool.Pool[source]

Given the max connection pool size and the max channel size create a channel Pool.

Parameters:
  • pool_size (integer) – Max size for the underlying connection Pool.
  • channel_size (integer) – Max size for the channel Pool.
logger
loglevel
static register_consumer(sub_channel, consumer, queue_name)[source]

Given a channel, a consumer function and a queue name register & start the consumption.

Parameters:
  • sub_channel (aio_pika.Channel) – An aio-pika Channel used for the subscriotion.
  • consumer (Callable) – Consumer function that will handle incoming messages in the queue.
  • queue_name (string) – Name of the queue to subscribe to.
run() → None[source]

Helper function implementing the synchronous boilerplate for initilization and teardown.

start()[source]

Asynchronous runtime for the worker, responsible of managing and maintaining async context open.

start_consume()[source]
start_rpc() → None[source]

Asynchronous runtime for the worker, responsible of managing and maintaining async context open.

Module contents

Top-level package for wcraas_common.