Jump to >


A manager for tracking and working with integrations.

class IntegrationManager(config_model)[source]

Bases: object

Manages integrations with third-party services.

The manager keeps track of the integrations registered by extensions or other components of an application, providing the ability to register new ones, unregister existing ones, and list any that are currently enabled.

It also manages the lookups of configurations for integrations, taking care to cache the lookups for any integrations and invalidate them when a configuration has been updated.


type – The model used to store configuration data. This is a subclass of djblets.integrations.models.BaseIntegrationConfig.


bool – The integration manager is enabled and can be used for registering, unregistering, and otherwise using integrations. If this is False, then shutdown() has been called, and it should be assumed that no integrations are registered or need to be unregistered.


Initialize the integration manager.

Parameters:config_model (type) – The model used to store configuration data. This must be a subclass of djblets.integrations.models.BaseIntegrationConfig.

Shut down the integrations on this integration manager.

This should be called when the integration manager and integrations will no longer be used. It will shut down every integration and unregister all integrations.


Return all the integration classes that have been registered.

This is not sorted in any particular order. It is up to the caller to determine the correct sorting order.

Yields:type – The registered integration classes.

Return an integration instance for a given ID.

Parameters:integration_id (unicode) – The integration ID that was registered.
Returns:The integration instance.
Return type:djblets.integrations.integration.Integration
Raises:djblets.integrations.errors.IntegrationNotRegisteredError – The integration class provided wasn’t registered.

Return all the integration instances.

This is not sorted in any particular order. It is up to the caller to determine the correct sorting order.

Yields:djblets.integrations.integration.Integration – The integration instances.
get_integration_configs(integration_cls=None, **filter_kwargs)[source]

Return a list of saved integration configurations.

By default, all configurations will be returned for all integrations, including configurations that are disabled. This can be filtered down by specifying an integration class and/or by filtering by fields in the model through keyword arguments.

Each set of results for a unique combination of integration class and filter arguments will be cached locally, to speed up further lookups. This cache can be flushed using clear_configs_cache() or clear_all_configs_cache(), and will be automatically cleared when cnofigurations are added, updated, or removed.

  • integration_cls (type, optional) – The integration class to filter by.
  • **filter_kwargs (dict, optional) – Keyword arguments to filter by. Each must match a field and value on the model.

A list of saved integration configurations matching the query.

Return type:

list of djblets.integrations.models.BaseIntegrationConfig

clear_configs_cache(integration_cls=None, **filter_kwargs)[source]

Clear the configuration cache matching the given filters.

This is used to clear a subset of the configs cache, matching the exact query arguments passed to a previous call to get_integration_configs().

To clear the entire cache, use clear_all_configs_cache().

  • integration_cls (type, optional) – The integration class for the filter.
  • **filter_kwargs (dict, optional) – Keyword arguments for the filter.

Clear the entire configuration cache.

This will force all future lookups to re-query the database. To clear only a subset of the cache, use clear_configs_cache().


Return whether the integration manager has expired state.

Returns:True if there’s either expired configuration state or integrations that need their enabled state recalculated.
Return type:bool

Check for and handle expired integration state.

If the configurations of one or more integrations have been updated by another process, or there are new integrations registered that may need to be enabled, this method will reset the cache state and re-calculate the integrations to enable/disable.


Register a class for an integration.

This will instantiate the integration and make it available for new configurations.


integration_cls (type) – The integration class to register.


The new instance of the registered integration class.

Return type:



Unregister a class for an integration.

The integration instance will be shut down, and the integration will no longer be made available for any further configuration.

If there is an error shutting down the integration, the output will be logged, but no error will be returned.

Parameters:integration_cls (type) – The integration class to unregister.
Raises:djblets.integrations.errors.IntegrationNotRegisteredError – The integration class was not previously registered.

Return all integration manager instances.

This will return all the integration managers that have been constructed. The order is not guaranteed.

Returns:The list of IntegrationManager instances.
Return type:list

Shut down all integration managers.

This is called automatically when the process exits, but can be run manually.