ccproxy.core.plugins.hooks.manager¶
ccproxy.core.plugins.hooks.manager
¶
Hook execution manager for CCProxy.
This module provides the HookManager class which handles the execution of hooks for various events in the system. It ensures proper error isolation and supports both async and sync hooks.
HookManager
¶
Manages hook execution with error isolation and async/sync support.
The HookManager is responsible for emitting events to registered hooks and ensuring that hook failures don't crash the system. It handles both async and sync hooks by running sync hooks in a thread pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
HookRegistry
|
The hook registry to get hooks from |
required |
background_manager
|
BackgroundHookThreadManager | None
|
Optional background thread manager for fire-and-forget execution |
None
|
Source code in ccproxy/core/plugins/hooks/manager.py
emit
async
¶
Emit an event to all registered hooks.
Creates a HookContext with the provided data and emits it to all hooks registered for the given event. Handles errors gracefully to ensure one failing hook doesn't affect others.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event
|
HookEvent
|
The event to emit |
required |
data
|
dict[str, Any] | None
|
Optional data dictionary to include in context |
None
|
fire_and_forget
|
bool
|
If True, execute hooks in background thread (default) |
True
|
**kwargs
|
Any
|
Additional context fields (request, response, provider, etc.) |
{}
|
Source code in ccproxy/core/plugins/hooks/manager.py
emit_with_context
async
¶
Emit an event using a pre-built HookContext.
This is useful when you need to build the context with specific metadata before emitting the event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
HookContext
|
The HookContext to emit |
required |
fire_and_forget
|
bool
|
If True, execute hooks in background thread (default) |
True
|
Source code in ccproxy/core/plugins/hooks/manager.py
shutdown
¶
Shutdown the background hook processing.
This method should be called during application shutdown to ensure proper cleanup of the background thread.