charmhelpers.core.reactive.decorators¶
hook |
Register the decorated function to run when the current hook matches any of the hook_patterns . |
not_unless |
Assert that the decorated function can only be called if the desired_states are active. |
only_once |
Ensure that the decorated function is only executed the first time it is called. |
when |
Register the decorated function to run when all desired_states are active. |
when_file_changed |
Register the decorated function to run when one or more files have changed. |
when_not |
Register the decorated function to run when not all desired_states are active. |
-
charmhelpers.core.reactive.decorators.
hook
(*hook_patterns)¶ Register the decorated function to run when the current hook matches any of the
hook_patterns
.The hook patterns can use the
{interface:...}
and{A,B,...}
syntax supported byany_hook()
.If the hook is a relation hook, an instance of that relation class will be passed in to the decorated function.
For example, to match any joined or changed hook for the relation providing the
mysql
interface:class MySQLRelation(RelationBase): @hook('{provides:mysql}-relation-{joined,changed}') def joined_or_changed(self): pass
-
charmhelpers.core.reactive.decorators.
not_unless
(*desired_states)¶ Assert that the decorated function can only be called if the desired_states are active.
Note that, unlike
when()
, this does not trigger the decorated function if the states match. It only raises an exception if the function is called when the states do not match.This is primarily for informational purposes and as a guard clause.
-
charmhelpers.core.reactive.decorators.
only_once
(action)¶ Ensure that the decorated function is only executed the first time it is called.
This can be used on reactive handlers to ensure that they are only triggered once, even if their conditions continue to match on subsequent calls, even across hook invocations.
-
charmhelpers.core.reactive.decorators.
when
(*desired_states)¶ Register the decorated function to run when all
desired_states
are active.This decorator will pass zero or more relation instances to the handler, if any of the states are associated with relations. If so, they will be passed in in the same order that the states are given to the decorator.
Note that handlers whose conditions match are triggered at least once per hook invocation.
-
charmhelpers.core.reactive.decorators.
when_file_changed
(*filenames, **kwargs)¶ Register the decorated function to run when one or more files have changed.
Parameters: - filenames (list) – The names of one or more files to check for changes.
- hash_type (str) – The type of hash to use for determining if a file has changed. Defaults to ‘md5’. Must be given as a kwarg.
-
charmhelpers.core.reactive.decorators.
when_not
(*desired_states)¶ Register the decorated function to run when not all desired_states are active.
This decorator will never cause arguments to be passed to the handler.
Note that handlers whose conditions match are triggered at least once per hook invocation.