DagsterDocs

Hooks

@dagster.success_hook(name=None, required_resource_keys=None)[source]

Create a hook on step success events with the specified parameters from the decorated function.

Parameters
  • name (Optional[str]) – The name of this hook.

  • required_resource_keys (Optional[AbstractSet[str]]) – Keys for the resources required by the hook.

Examples

@success_hook(required_resource_keys={'slack'})
def slack_message_on_success(context):
    message = 'solid {} succeeded'.format(context.solid.name)
    context.resources.slack.send_message(message)

@success_hook
def do_something_on_success(context):
    do_something()
@dagster.failure_hook(name=None, required_resource_keys=None)[source]

Create a hook on step failure events with the specified parameters from the decorated function.

Parameters
  • name (Optional[str]) – The name of this hook.

  • required_resource_keys (Optional[AbstractSet[str]]) – Keys for the resources required by the hook.

Examples

@failure_hook(required_resource_keys={'slack'})
def slack_message_on_failure(context):
    message = 'solid {} failed'.format(context.solid.name)
    context.resources.slack.send_message(message)

@failure_hook
def do_something_on_failure(context):
    do_something()
class dagster.HookDefinition(name, hook_fn, required_resource_keys=None, decorated_fn=None)[source]

Define a hook which can be triggered during a solid execution (e.g. a callback on the step execution failure event during a solid execution).

Parameters
  • name (str) – The name of this hook.

  • hook_fn (Callable) – The callback function that will be triggered.

  • required_resource_keys (Optional[AbstractSet[str]]) – Keys for the resources required by the hook.

class dagster.HookContext(step_execution_context, hook_def)[source]

The context object available to a hook function on an DagsterEvent.

log

Centralized log dispatch from user code.

Type

DagsterLogManager

hook_def

The hook that the context object belongs to.

Type

HookDefinition

solid

The solid instance associated with the hook.

Type

Solid

step_key

The key for the step where this hook is being triggered.

Type

str

resources

Resources available in the hook context.

Type

Resources

solid_config

The parsed config specific to this solid.

Type

Any

pipeline_name

The name of the pipeline where this hook is being triggered.

Type

str

run_id

The id of the run where this hook is being triggered.

Type

str

mode_def

The mode with which the pipeline is being run.

Type

ModeDefinition

property solid_exception

The thrown exception in a failed solid.

Returns

the exception object, None if the solid execution succeeds.

Return type

Optional[BaseException]

property solid_output_values

The computed output values.

Returns a dictionary where keys are output names and the values are:
  • the output values in the normal case

  • a dictionary from mapping key to corresponding value in the mapped case

dagster.build_hook_context(resources=None, mode_def=None)[source]

Builds hook context from provided parameters.

build_hook_context can be used as either a function or a context manager. If there is a provided resource to build_hook_context that is a context manager, then it must be used as a context manager. This function can be used to provide the context argument to the invocation of a hook definition.

Parameters
  • resources (Optional[Dict[str, Any]]) – The resources to provide to the context. These can either be values or resource definitions.

  • mode_def (Optional[ModeDefinition]) – The mode definition used with the context.

Examples

context = build_hook_context()
hook_to_invoke(context)

with build_hook_context(resources={"foo": context_manager_resource}) as context:
    hook_to_invoke(context)