Entrypoints

class q2_sdk.core.entrypoint.BaseEntryPoint[source]

This is largely based off of the way Django organizes its Management Commands.

We do not need the power nor the flexibility that Django provides here, but it’s such a great pattern, it seems a shame to reinvent the wheel.

Basic idea: When running q2 at the command line, each file in the entrypoints folder of the SDK that ends in .py and does not start with _ is loaded. The parser is built off of what lives in add_arguments, while the action when run is determined by what lives in the handle function.

name: The command line parameter to be called (name=inspect means q2 inspect) help: Help message at the command line run_forever: If True, the asyncio loop will not exit after completion of handle function

property cache: Q2CacheClient

Instantiates a communication object between this extension and the pymemcache library. Cache can be configured via configuration.settings.CACHE.

Returns:

Instantiated pymemcache.cache.Client object

async async_run_forever_cleanup()[source]

Hook as the run forever loop is terminating

run_forever_cleanup()[source]

Hook for any cleanup necessary after run forever loop is terminated

add_arguments(parser)[source]

Hook for subclassed EntryPoints to add custom arguments.

setup(logger)[source]

Registers a logger in self.logger with all appropriate filters

generate_completion()[source]

Works with q2 install_completion to create completion file in <root>/.antilles/entrypoints/<self.name>

async handle(*args, **kwargs)[source]

The actual logic of the command. Subclasses must implement this method.

class q2_sdk.core.entrypoint_periodic.PeriodicJobEntryPoint[source]

Same as BaseEntryPoint but specialized for registering with a Cron-like system. Adds more logging and defined success/failure hooks for easier debugging when run overnight, for instance.

setup(logger)[source]

Ensures periodic jobs will log in the format of request handlers

async run()[source]

Code here will be executed when periodic job starts

async handle(*args, **kwargs)[source]

The actual logic of the command. Subclasses must implement this method.

async on_pre_run()[source]

Called before run()

async on_success(run_result)[source]

Called after run() if it did not raise an Exception.

If run() returns a value, it will be passed as the first parameter here.

async on_failure(err, failure_dict)[source]

Called after run() if it raised an Exception.

By default, all local variables (failure_dict) will be logged on failure. This hook exists if additional failure processing is desired.