class documentation

class AsyncBaseProgram: (source)

Constructor: AsyncBaseProgram()

View In Hierarchy

This generic base program class is intended to be used as a building block through inheritance when you are creating a server program.

Any methods that you need to change, you override it using polymorphism.

RabbitMQ is used for sending messages to external programs. Messages that are to be sent to the RabbitMQ will be stored offline if the communication goes down and will be re-sent when the communication is re-established.

Subscribe temporarily for the following RabbitMQ message topic(s):
  • Health.Request
Sends RabbitMQ messages with the following topic(s):
  • Error.Message.AsyncExampleProgram.<server>
  • Health.Response.AsyncExampleProgram.<server>
Method __init__ The class constructor.
Async Method exit_prog Stop the server program.
Async Method run Start the server program.
Instance Variable error Program exit error status.
Instance Variable future Asyncio Future handle (used for handling fatal error program exit).
Instance Variable ini Handles INI file parameters for this program.
Instance Variable location Current program name, including the path.
Instance Variable log Handle colored and dynamic filter logging.
Instance Variable program Current program name, used for logging.
Instance Variable scheduler Handles periodic ini file change checks.
Instance Variable worker Handles the bulk of the work for this program.
Method _demo_purposes_only This method is only used for demo.
Async Method _fatal_error_dump Report error and trigger a fatal program exit.
Async Method _handle_ini_error Trigger a fatal program exit when errors found and fatal==True.
Async Method _initiate_resources Initiate resources used by the program.
Async Method _initiate_unique_resources Initiate unique resources used by the program.
Async Method _schedule_ini_check Extract and validate INI file content if the Ini file is updated.
Async Method _schedule_unique_ini_check Send INI file update notification to the worker.
def __init__(self): (source)

The class constructor.

async def exit_prog(self): (source)

Stop the server program.

async def run(self): (source)

Start the server program.

The following actions are performed:
  • Initiate used resources.
  • Start dynamic log level handling.
  • Wait for program termination.

Program exit error status.

Asyncio Future handle (used for handling fatal error program exit).

Handles INI file parameters for this program.

location: Path = (source)

Current program name, including the path.

Handle colored and dynamic filter logging.

Current program name, used for logging.

scheduler: apscheduler.schedulers.asyncio.AsyncIOScheduler = (source)

Handles periodic ini file change checks.

Handles the bulk of the work for this program.

def _demo_purposes_only(self): (source)

This method is only used for demo.

It should be removed in normal code usage.

async def _fatal_error_dump(self, error: Exception, suppress: bool = False): (source)

Report error and trigger a fatal program exit.

When Suppress=True, no ErrorMessage is sent to RabbitMQ and an exception traceback is not logged.

Parameters
error:ExceptionCurrent exception.
suppress:boolSuppress traceback dump and sending ErrorMessage.
async def _handle_ini_error(self, fatal: bool): (source)

Trigger a fatal program exit when errors found and fatal==True.

Parameters
fatal:boolIs the error fatal or not?
async def _initiate_resources(self): (source)

Initiate resources used by the program.

The following actions are performed:
  • Initiate unique resources used by the program.
  • Start Ini file change supervision (every 5 seconds).
  • Setup waits for program termination.
@abstractmethod
async def _initiate_unique_resources(self): (source)

Initiate unique resources used by the program.

Abstract method that needs to be overridden.

The following actions are performed:
  • Validate INI file content.
  • Start log processing.
  • Initiate current worker.
async def _schedule_ini_check(self): (source)

Extract and validate INI file content if the Ini file is updated.

This method is called by the AsyncIOScheduler every 5 seconds.

A RuntimeError is raised if the validation of the changed INI file content fails, otherwise the worker is notified if the relevant parameter has changed.

Raises
RuntimeErrorWhen INI file validation fails.
async def _schedule_unique_ini_check(self): (source)

Send INI file update notification to the worker.

If you need it, override it using normal polymorphism.