djblets.integrations.manager¶
A manager for tracking and working with integrations.
- class IntegrationManager(config_model: Type[BaseIntegrationConfig])[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.
- __init__(config_model: Type[BaseIntegrationConfig]) None [source]¶
Initialize the integration manager.
- Parameters:
config_model (
type
) – The model used to store configuration data. This must be a subclass ofdjblets.integrations.models.BaseIntegrationConfig
.
- config_model: Type[BaseIntegrationConfig]¶
The model used to store configuration data.
- enabled: bool¶
Whether the integration manager is enabled.
When enabled, the integration manager can be used for registering, unregistering, and otherwise using integrations.
If this is
False
, thenshutdown()
has been called, and it should be assumed that no integrations are registered or need to be unregistered.
- shutdown() None [source]¶
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.
- get_integration_classes() Iterable[IntegrationClassType] [source]¶
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.
- get_integration(integration_id: str) Integration [source]¶
Return an integration instance for a given ID.
- Parameters:
integration_id (
str
) – The integration ID that was registered.- Returns:
The integration instance.
- Return type:
- Raises:
djblets.integrations.errors.IntegrationNotRegisteredError – The integration class provided wasn’t registered.
- get_integrations() Iterable[Integration] [source]¶
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: Optional[IntegrationClassType] = None, **filter_kwargs) Sequence[BaseIntegrationConfig] [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()
orclear_all_configs_cache()
, and will be automatically cleared when cnofigurations are added, updated, or removed.- Parameters:
- Returns:
A list of saved integration configurations matching the query.
- Return type:
- clear_configs_cache(integration_cls: Optional[IntegrationClassType] = None, **filter_kwargs) None [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()
.
- clear_all_configs_cache() None [source]¶
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()
.
- is_expired() bool [source]¶
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:
- check_expired() None [source]¶
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_integration_class(integration_cls: IntegrationClassType) Integration [source]¶
Register a class for an integration.
This will instantiate the integration and make it available for new configurations.
- Parameters:
integration_cls (
type
) – The integration class to register.- Returns:
The new instance of the registered integration class.
- Return type:
- Raises:
djblets.integrations.errors.IntegrationAlreadyRegisteredError – The integration class was already registered.
djblets.integrations.errors.IntegrationConstructionError – Error initializing an instance of the integration. The integration will not be registered.
- __annotations__ = {'_integration_classes': 'Dict[str, IntegrationClassType]', '_integration_configs': 'Dict[str, List[BaseIntegrationConfig]]', '_integration_instances': 'Dict[str, Integration]', '_needs_recalc': 'bool', 'config_model': 'Type[BaseIntegrationConfig]', 'enabled': 'bool'}¶
- unregister_integration_class(integration_cls: IntegrationClassType) None [source]¶
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.
- get_integration_managers() Sequence[IntegrationManager] [source]¶
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: