Base Class
allsky_base
¶
ALLSKYMODULEBASE(params, event)
¶
Base class for Allsky processing modules.
This class provides a common interface and helper methods that Allsky modules can inherit from. It handles:
- Storing the raw
paramsdictionary passed in from the flow. - Storing the
eventthat triggered the module (e.g. postcapture, periodic). - A simple debug mode that prints directly to stdout instead of using the shared logger.
- Unified parameter retrieval via :meth:
get_param, including support for "secret" parameters stored inenv.json(rather than in plain text module configuration). - A small compatibility layer around the historical
metaDataglobal, via themeta_datainstance attribute.
Initialize the module base with parameters and the triggering event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
dict
|
Dictionary of parameters passed to the module from the flow configuration. Typically this comes from the JSON module config. |
required |
event
|
str
|
Name of the event that triggered this module (for example,
|
required |
Side Effects
- Sets
self.paramsandself.eventfrom the arguments. - Sets
self.debugmode/self.debug_modebased on theALLSKYTESTMODEparameter. When True, messages are printed directly rather than sent to the Allsky logger. - Provides a compatibility bridge from the legacy global
metaDatato the instance attributemeta_dataif the latter has not been set on the subclass.
Notes
Subclasses are expected to define a meta_data attribute that
describes the module (arguments, defaults, secrets etc.). If that
is not present, this initializer will attempt to fall back to an
older global variable named metaData if it exists.
Source code in scripts/modules/allsky_base.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
debug_mode = self.debugmode
instance-attribute
¶
Originally metaData was a global variable but has since been replaced by meta_data as a class variable. This code will set hte class variable if its not been defined from the global variable if it is defined.
debug_log(message)
¶
Write a debug message only when debug mode is enabled.
This helper is intended for very chatty or development-only messages
that should never reach the normal Allsky logging system. It simply
prints the message to stdout if self.debug_mode is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Message to print when debug mode is active. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
Source code in scripts/modules/allsky_base.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
get_database_config()
¶
Return the resolved database configuration for the current Allsky setup.
This is a convenience wrapper around
:func:allsky_shared.get_database_config, which merges secrets from
env.json with settings from the Allsky configuration file.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
A dictionary containing at least:
|
Notes
This method does not open any connections itself; it only reads configuration that can be passed on to the database manager.
Source code in scripts/modules/allsky_base.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
get_param(param, default, target_type=str, use_default_if_blank=False)
¶
Retrieve a module parameter with optional type conversion and secret handling.
This method is the preferred way for modules to read configuration
values. It looks up the parameter in self.params, optionally
overrides it from env.json if the parameter is marked as a secret,
and then attempts to cast it to the requested type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
param
|
str
|
The parameter name to look up. |
required |
default
|
Any
|
Default value to return if the parameter is missing or cannot
be cast to |
required |
target_type
|
type
|
Type to cast the parameter value to (for example |
str
|
use_default_if_blank
|
bool
|
If True and the target type is |
False
|
Secret handling
If the module defines self.meta_data and it contains an
"argumentdetails" section, any parameter marked with
"secret": true will be read from Allsky's env.json using
the key <MODULE>_<PARAM> (both upper-cased). If the key is not
found in the env file, an error is logged via allsky_shared.log.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
The parameter value converted to |
Notes
- No exception is raised if casting fails; the default is silently used instead.
- This helper is designed to be resilient and safe to call from within modules without needing try/except at every call site.
Source code in scripts/modules/allsky_base.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
log(level, message, preventNewline=False, exitCode=None, sendToAllsky=False)
¶
Log a message via the shared Allsky logger or print in debug mode.
This is a thin wrapper around :func:allsky_shared.log that respects
the module's debug mode:
- If
self.debug_modeis True, the message is printed directly to stdout. - Otherwise, the call is forwarded to
allsky_shared.logwith the same arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
Log level as used by the Allsky logging system (for example, 0 for errors, higher numbers for more verbose output). |
required |
message
|
str
|
The message to log. |
required |
preventNewline
|
bool
|
If True, do not end the log line with a newline. Defaults to False. |
False
|
exitCode
|
int | None
|
If not None, the underlying logger may terminate the process with this exit code. Defaults to None. |
None
|
sendToAllsky
|
bool
|
When True, forwards the message into Allsky's Web UI message system as well as standard output, depending on logging level. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
None |
Source code in scripts/modules/allsky_base.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |