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: Union[list, tuple] = None, func_kwargs: dict = None, year: Union[int, str] = None, month: Union[int, str] = None, day: Union[int, str] = None, week: Union[int, str] = None, day_of_week: Union[int, str] = None, hour: Union[int, str] = None, minute: Union[int, str] = None, second: Union[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
|
Union[list, tuple]
|
list of positional arguments to call func with |
None
|
func_kwargs
|
dict
|
dict of keyword arguments to call func with |
None
|
year
|
Union[int, str]
|
4-digit year |
None
|
month
|
Union[int, str]
|
month (1-12) |
None
|
day
|
Union[int, str]
|
day of month (1-31) |
None
|
week
|
Union[int, str]
|
ISO week (1-53) |
None
|
day_of_week
|
Union[int, str]
|
number or name of weekday (0-6 or mon,tue,wed,thu,fri,sat,sun) |
None
|
hour
|
Union[int, str]
|
hour (0-23) |
None
|
minute
|
Union[int, str]
|
minute (0-59) |
None
|
second
|
Union[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
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 specified entity (though same hook can be bound multiple times).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hook
|
Callable[[str, 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[[str, 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 specified entity (though same hook can be bound multiple times).
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[[str, 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[[str, DataPointType], Union[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[[str, DataPointType], Union[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 specified entity_type
and attr_type
(though same hook can be bound
multiple times).
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], Union[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 specified entity_type (though same hook can be bound multiple times).
entity_type
and attribute specifications are validated, ValueError
is raised on failure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
hook
|
Callable[[str, dict], Union[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, str, 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, str, 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, str], 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, str], 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[[str, 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[[str, DataPointTask], Union[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 |