Yepher
08/08/2023, 7:40 PM@asset
def hello_world(context, slack: SlackResource) -> None:
<http://context.log.info|context.log.info>("start hello_world")
slack.get_client().chat_postMessage(
channel="#test_private_channel",
text="Hello, from Dagster! :dagster:",
)
# ... do stuff ....
<http://context.log.info|context.log.info>("After hello_world")
___init___.py
def slack_token():
# Parse the environment variable
secret = json.loads(os.getenv('dagsterSecret'))
# Extract connection parameters
slack_token = secret['slack_api_token']
return slack_token
defs = Definitions(
assets=all_assets,
# resources=resources_by_deployment_name[deployment_name],
# schedules=[core_assets_schedule],
# sensors=all_sensors,
resources={
"slack": SlackResource(token=slack_token()),
},
)
I would like to not have to set the slack token or put a garbage token for dev env. But if I do that, I get errors. Do you have any suggestions on handling this so I only use a valid Slack token on staging and prod?
I am leaning toward a Slack WebClient intercepter that does the "magic" I am after, but I wanted to check if there is something better/easier first.Sean Lopp
08/08/2023, 8:08 PMclass MockSlackResource(SlackResource):
def chat_postMessage(self, channel, text, unfurl_links):
msg = f"""
THIS IS A MOCK SLACK MESSAGE
Channel: {channel}
Message: {text}
Unfurl Links Bool: {unfurl_links}
"""
print(msg)
Then in definitions
dev_resources = {"slack": MockSlackResource(token="fake")}
prod_resources = {"slack": SlackResource(token=EnvVar("real"))}
resources = prod_resources if os.getenv("PROD") else dev_resources
Yepher
08/08/2023, 8:12 PMYepher
08/08/2023, 8:21 PMchat_postMessage
is not a method of SlackResource