dp3.common.callback_registrar ¶
CallbackRegistrar ¶
CallbackRegistrar(scheduler: Scheduler, task_executor: TaskExecutor, snap_shooter: SnapShooter, updater: Updater)
Interface for callback registration.
Source code in dp3/common/callback_registrar.py
scheduler_register ¶
scheduler_register(func: Callable, *, func_args: list | tuple = None, func_kwargs: dict = None, year: int | str = None, month: int | str = None, day: int | str = None, week: int | str = None, day_of_week: int | str = None, hour: int | str = None, minute: int | str = None, second: int | str = None, timezone: str = 'UTC', misfire_grace_time: int = 1) -> int
Register a function to be run at specified times.
Pass cron-like specification of when the function should be called, see docs of apscheduler.triggers.cron for details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
function or method to be called |
required |
func_args
|
list | tuple
|
list of positional arguments to call func with |
None
|
func_kwargs
|
dict
|
dict of keyword arguments to call func with |
None
|
year
|
int | str
|
4-digit year |
None
|
month
|
int | str
|
month (1-12) |
None
|
day
|
int | str
|
day of month (1-31) |
None
|
week
|
int | str
|
ISO week (1-53) |
None
|
day_of_week
|
int | str
|
number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun) |
None
|
hour
|
int | str
|
hour (0-23) |
None
|
minute
|
int | str
|
minute (0-59) |
None
|
second
|
int | str
|
second (0-59) |
None
|
timezone
|
str
|
Timezone for time specification (default is UTC). |
'UTC'
|
misfire_grace_time
|
int
|
seconds after the designated run time that the job is still allowed to be run (default is 1) |
1
|
Returns: job ID
Source code in dp3/common/callback_registrar.py
scheduler_register_once ¶
scheduler_register_once(func: Callable, *, func_args: list | tuple = None, func_kwargs: dict = None, misfire_grace_time: int = 60) -> int
Register a function to run once when the scheduler starts.
Source code in dp3/common/callback_registrar.py
register_task_hook ¶
Registers one of available task hooks
See: TaskGenericHooksContainer
in task_hooks.py
Source code in dp3/common/callback_registrar.py
register_allow_entity_creation_hook ¶
Registers passed hook to allow entity creation.
Binds hook to the specified entity. A hook can only be bound once to each entity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[AnyEidT, DataPointTask], bool]
|
|
required |
entity
|
str
|
specifies entity type |
required |
Source code in dp3/common/callback_registrar.py
register_on_entity_creation_hook ¶
register_on_entity_creation_hook(hook: Callable[[AnyEidT, DataPointTask], list[DataPointTask]], entity: str, refresh: SharedFlag = None, may_change: list[list[str]] = None)
Registers passed hook to be called on entity creation.
Binds hook to the specified entity. A hook can only be bound once to each entity.
Allows registration of refreshing on configuration changes, if refresh is specified.
In that case, may_change must be specified.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[AnyEidT, DataPointTask], list[DataPointTask]]
|
|
required |
entity
|
str
|
specifies entity type |
required |
refresh
|
SharedFlag
|
If specified, registered hook will be called on configuration changes.
Pass |
None
|
may_change
|
list[list[str]]
|
each item should specify an attribute that |
None
|
Source code in dp3/common/callback_registrar.py
register_entity_hook ¶
Registers one of available task entity hooks
Deprecated
This method is deprecated, use register_on_entity_creation_hook
or register_allow_entity_creation_hook instead.
See: TaskEntityHooksContainer
in task_hooks.py
Source code in dp3/common/callback_registrar.py
register_on_new_attr_hook ¶
register_on_new_attr_hook(hook: Callable[[AnyEidT, DataPointType], None | list[DataPointTask]], entity: str, attr: str, refresh: SharedFlag = None, may_change: list[list[str]] = None)
Registers passed hook to be called on new attribute datapoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[AnyEidT, DataPointType], None | list[DataPointTask]]
|
|
required |
entity
|
str
|
specifies entity type |
required |
attr
|
str
|
specifies attribute name |
required |
refresh
|
SharedFlag
|
If specified, registered hook will be called on configuration changes.
Pass |
None
|
may_change
|
list[list[str]]
|
each item should specify an attribute that |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If entity and attr do not specify a valid attribute, a ValueError is raised. |
Source code in dp3/common/callback_registrar.py
register_attr_hook ¶
Registers one of available task attribute hooks
Deprecated
This method is deprecated, use register_on_new_attr_hook instead.
See: TaskAttrHooksContainer
in task_hooks.py
Source code in dp3/common/callback_registrar.py
register_timeseries_hook ¶
register_timeseries_hook(hook: Callable[[str, str, list[dict]], list[DataPointTask]], entity_type: str, attr_type: str)
Registers passed timeseries hook to be called during snapshot creation.
Binds hook to the specified entity_type and attr_type. A hook can only be bound
once to each entity attribute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[str, str, list[dict]], list[DataPointTask]]
|
|
required |
entity_type
|
str
|
specifies entity type |
required |
attr_type
|
str
|
specifies attribute type |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If entity_type and attr_type do not specify a valid timeseries attribute, a ValueError is raised. |
Source code in dp3/common/callback_registrar.py
register_correlation_hook ¶
register_correlation_hook(hook: Callable[[str, dict], None | list[DataPointTask]], entity_type: str, depends_on: list[list[str]], may_change: list[list[str]])
Registers passed hook to be called during snapshot creation.
Binds hook to the specified entity type and dependency context. Duplicate hook IDs are rejected.
entity_type and attribute specifications are validated, ValueError is raised on failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[str, dict], None | list[DataPointTask]]
|
|
required |
entity_type
|
str
|
specifies entity type |
required |
depends_on
|
list[list[str]]
|
each item should specify an attribute that is depended on in the form of a path from the specified entity_type to individual attributes (even on linked entities). |
required |
may_change
|
list[list[str]]
|
each item should specify an attribute that |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
On failure of specification validation. |
Source code in dp3/common/callback_registrar.py
register_correlation_hook_with_master_record ¶
register_correlation_hook_with_master_record(hook: Callable[[str, dict, dict], None | list[DataPointTask]], entity_type: str, depends_on: list[list[str]], may_change: list[list[str]])
Registers passed hook to be called during snapshot creation.
Identical to register_correlation_hook, but the hook also receives the master record.
Binds hook to the specified entity type and dependency context. Duplicate hook IDs are rejected.
entity_type and attribute specifications are validated, ValueError is raised on failure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[str, dict, dict], None | list[DataPointTask]]
|
|
required |
entity_type
|
str
|
specifies entity type |
required |
depends_on
|
list[list[str]]
|
each item should specify an attribute that is depended on in the form of a path from the specified entity_type to individual attributes (even on linked entities). |
required |
may_change
|
list[list[str]]
|
each item should specify an attribute that |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
On failure of specification validation. |
Source code in dp3/common/callback_registrar.py
register_snapshot_init_hook ¶
Registers passed hook to be called before a run of snapshot creation begins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[], list[DataPointTask]]
|
|
required |
Source code in dp3/common/callback_registrar.py
register_snapshot_finalize_hook ¶
Registers passed hook to be called after a run of snapshot creation ends.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[], list[DataPointTask]]
|
|
required |
Source code in dp3/common/callback_registrar.py
register_periodic_update_hook ¶
register_periodic_update_hook(hook: Callable[[str, AnyEidT, dict], list[DataPointTask]], hook_id: str, entity_type: str, period: ParsedTimedelta)
Registers a callback for periodic update of entities of the specified type.
The callback receives the entity type, the entity ID and the master record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[str, AnyEidT, dict], list[DataPointTask]]
|
|
required |
hook_id
|
str
|
specifies hook ID |
required |
entity_type
|
str
|
specifies entity type |
required |
period
|
ParsedTimedelta
|
specifies period of the callback |
required |
Source code in dp3/common/callback_registrar.py
register_periodic_eid_update_hook ¶
register_periodic_eid_update_hook(hook: Callable[[str, AnyEidT], list[DataPointTask]], hook_id: str, entity_type: str, period: ParsedTimedelta)
Registers a callback for periodic update of entities of the specified type.
The callback receives the entity type and the entity ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hook
|
Callable[[str, AnyEidT], list[DataPointTask]]
|
|
required |
hook_id
|
str
|
specifies hook ID |
required |
entity_type
|
str
|
specifies entity type |
required |
period
|
ParsedTimedelta
|
specifies period of the callback |
required |
Source code in dp3/common/callback_registrar.py
on_entity_creation_in_snapshots ¶
on_entity_creation_in_snapshots(model_spec: ModelSpec, run_flag: SharedFlag, original_hook: Callable[[AnyEidT, DataPointTask], list[DataPointTask]], etype: str, record: dict) -> list[DataPointTask]
Wrapper for on_entity_creation hooks to enable running as a snapshot callback.
Source code in dp3/common/callback_registrar.py
on_attr_change_in_snapshots ¶
on_attr_change_in_snapshots(model_spec: ModelSpec, run_flag: SharedFlag, original_hook: Callable[[AnyEidT, DataPointTask], list[DataPointTask] | None], etype: str, record: dict) -> list[DataPointTask]
Wrapper for on_entity_creation hooks to enable running as a snapshot callback.
Source code in dp3/common/callback_registrar.py
reload_module_config ¶
reload_module_config(log: Logger, platform_config: PlatformConfig, modules: dict, module: str) -> None
Reloads configuration of a module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log
|
Logger
|
log to write messages to |
required |
platform_config
|
PlatformConfig
|
Platform configuration |
required |
modules
|
dict
|
Dictionary of loaded modules by their names |
required |
module
|
str
|
Name of the module to reload |
required |
Returns:
| Type | Description |
|---|---|
None
|
Module's configuration |