quorum

Base

quorum.APP = None

The reference to the top level application object that is being handled by quorum. This value is used across the quorum infra-structure to access flask data and capabilities.

Note

Changing this value directly should be done with care as it may create undesired results. To set/start this value use the quorum.load() function instead.

quorum.load(app=None, name=None, secret_key=None, execution=True, redis_session=False, mongo_database=None, logger=None, models=None, **kwargs)

Initial loader function responsible for the overriding of the flask loading system and for the loading of configuration.

Note

This function should be called inside you main app file failure to do so may result in unexpected behavior.

Parameters:
  • app (Application) – The optional flask application object to be used in the loading of quorum (useful for self managed apps).
  • name (String) – The name to be used to describe the application for the management of internal values.
  • secret_key (String) – The secret seed value to be used for cryptographic operations under flask (eg: client side sessions) this value should be shared among all the pre-fork instances.
  • execution (bool) – Flag indicating if the (background) execution thread should be started providing the required support for background tasks.
  • redis_session (bool) – If the session management for the flask infra-structure should be managed using a server side session with support from redis.
  • mongo_database (String) – The default name of the database to be used when using the mongo infra-structure.
  • logger (String) – The name to be used as identification for possible logger files created by the logging sub-module.
  • models (Module) – The module containing the complete set of model classes to be used by the data infra-structure (eg: mongo).
Return type:

Application

Returns:

The application that is used by the loaded quorum environment in case one was provided that is retrieved, otherwise the newly created one is returned instead.

quorum.unload()

Unloads the current quorum instance, after this call no more access to the quorum facilities is allowed.

Warning

Use this function with care as it may result in unexpected behavior from a developer point of view.

Note

After the call to this method most of the functionally of quorum will become unavailable until further call to quorum.load().

quorum.run_back(callable, args=, []kwargs={}, target_time=None, callback=None)

Runs the provided callable (function, method, etc) in a separated thread context under submission of a queue system. It’s possible to control the runtime for the execution with the target_time argument and it’s also possible to be notified of the end of the execution providing a callable to the callback parameter.

Warning

The execution is not guaranteed as the system process may be interrupted and resuming of the execution would not be possible.

Parameters:
  • callable (Function) – The callable object to be called in a separated execution environment.
  • args (Dictionary) – The list of unnamed argument values to be send to the callable upon execution.
  • args – The dictionary of named argument values to be send to the callable upon execution.
  • target_time (float) – The target timestamp value for execution, in case it’s not provided the current time is used as the target one.
  • callback (Function) – The callback function to be called upon finishing the execution of the callable, in case an error (exception) on executing the callback the error is passed as error argument.
quorum.run_background(callable, args=, []kwargs={}, target_time=None, callback=None)

Runs the provided callable (function, method, etc) in a separated thread context under submission of a queue system. It’s possible to control the runtime for the execution with the target_time argument and it’s also possible to be notified of the end of the execution providing a callable to the callback parameter.

Warning

The execution is not guaranteed as the system process may be interrupted and resuming of the execution would not be possible.

Parameters:
  • callable (Function) – The callable object to be called in a separated execution environment.
  • args (Dictionary) – The list of unnamed argument values to be send to the callable upon execution.
  • args – The dictionary of named argument values to be send to the callable upon execution.
  • target_time (float) – The target timestamp value for execution, in case it’s not provided the current time is used as the target one.
  • callback (Function) – The callback function to be called upon finishing the execution of the callable, in case an error (exception) on executing the callback the error is passed as error argument.

Mail / SMTP

quorum.send_mail(app=None, subject='', sender=None, receivers=, []data=None, plain=None, rich=None, context={})

Sends an email message using the provided SMTP_HOST, SMTP_USER and SMTP_PASSWORD configurations.

The email message is sent under the alternative mime type so that both the plain text and the rich text (html) parts are sent in the same message.

The plain and rich arguments allow the user to process a template with the context provided by the context map.

Warning

This is a blocking call and as such the control flow may block for more that a second, if you want a non blocking (asynchronous) call please use quorum.send_mail_a().

Parameters:
  • app (Application) – Optional application object to be used for the rendering operation as the main object for flask. In case this value is not provided the global quorum.APP value is used instead (fallback).
  • subject (String) – The mime subject to be sent with this message, note that if this value is not set many spam filters will consider the message as spam.
  • sender (String) – The email (and name) of the sender of the email, in case this value is not set the SMTP_USER variable is used instead.
  • receivers (List) – The list of receivers (with email and name) for which the email will be sent.
  • data (String) – The buffer containing the data to be used for both the plain and the rich text parts in case the template associated arguments are not set or in case the rendering is not successful.
  • plain (String) – Relative path to the plain text template to be used for the rendering of the email, this path must be relative to the templates folder.
  • rich (String) – Relative path to the rich text template to be used for the rendering of the email, this path must be relative to the templates folder.
  • context (Dictionary) – The map containing the complete set of variables that are going to be “exposed” to the template rendering engine for both the plain and the rich.
quorum.send_mail_a(*args, **kwargs)

Asynchronous call to the quorum.send_mail() function that is executed in a different thread from the current one. The currently loaded queue system is used for the sending of the email, for more information check on quorum.run_background() .

Note

The arguments to be send for this function are the same as the one present in the original quorum.send_mail() function.

MongoDB

enumerate(sequence[, start=0])

Return an iterator that yields tuples of an index and an item of the

Table Of Contents

Related Topics

This Page

Fork me on GitHub