Skip to content

Commit

Permalink
move slack apidoc example to op/job (#6855)
Browse files Browse the repository at this point in the history
  • Loading branch information
sryza committed Mar 2, 2022
1 parent 4d4d6a7 commit e9834b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 30 deletions.
36 changes: 16 additions & 20 deletions python_modules/libraries/dagster-slack/dagster_slack/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,22 @@ def slack_on_failure(
.. code-block:: python
@slack_on_failure("#foo", dagit_base_url="http://localhost:3000")
@pipeline(...)
def my_pipeline():
@job(...)
def my_job():
pass
.. code-block:: python
def my_message_fn(context: HookContext) -> str:
return "Solid {solid_name} failed!".format(
solid_name=context.solid
)
return f"Op {context.op} failed!"
@solid
def a_solid(context):
@op
def an_op(context):
pass
@pipeline(...)
def my_pipeline():
a_solid.with_hooks(hook_defs={slack_on_failure("#foo", my_message_fn)})
@job(...)
def my_job():
an_op.with_hooks(hook_defs={slack_on_failure("#foo", my_message_fn)})
"""

Expand Down Expand Up @@ -91,24 +89,22 @@ def slack_on_success(
.. code-block:: python
@slack_on_success("#foo", dagit_base_url="http://localhost:3000")
@pipeline(...)
def my_pipeline():
@job(...)
def my_job():
pass
.. code-block:: python
def my_message_fn(context: HookContext) -> str:
return "Solid {solid_name} worked!".format(
solid_name=context.solid
)
return f"Op {context.solid} worked!"
@solid
def a_solid(context):
@op
def an_op(context):
pass
@pipeline(...)
def my_pipeline():
a_solid.with_hooks(hook_defs={slack_on_success("#foo", my_message_fn)})
@job(...)
def my_job():
an_op.with_hooks(hook_defs={slack_on_success("#foo", my_message_fn)})
"""

Expand Down
18 changes: 8 additions & 10 deletions python_modules/libraries/dagster-slack/dagster_slack/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,20 @@ def slack_resource(context):
import os
from dagster import solid, execute_pipeline, ModeDefinition
from dagster import job, op
from dagster_slack import slack_resource
@solid(required_resource_keys={'slack'})
def slack_solid(context):
@op(required_resource_keys={'slack'})
def slack_op(context):
context.resources.slack.chat_postMessage(channel='#noise', text=':wave: hey there!')
@pipeline(
mode_defs=[ModeDefinition(resource_defs={'slack': slack_resource})],
)
def slack_pipeline():
slack_solid()
@job(resource_defs={'slack': slack_resource})
def slack_job():
slack_op()
execute_pipeline(
slack_pipeline, {'resources': {'slack': {'config': {'token': os.getenv('SLACK_TOKEN')}}}}
slack_job.execute_in_process(
run_config={'resources': {'slack': {'config': {'token': os.getenv('SLACK_TOKEN')}}}}
)
"""
Expand Down

0 comments on commit e9834b4

Please sign in to comment.