https://dagster.io/ logo
#ask-community
Title
# ask-community
j

junsik KIM

08/03/2022, 10:52 AM
Help ~ “slack failure sensor” not working. Can’t send slack message from dagster. No matter what I try, it doesn’t work. The source code is as below. #repository
Copy code
repository.py

from dagster import repository
from ts_dagster.jobs.say_hello import say_hello_job
from ts_dagster.schedules.my_hourly_schedule import my_hourly_schedule
from ts_dagster.sensors.slack_on_failure_sensor import make_slack_on_failure_sensor

@repository
def ts_dagster():
    jobs = [say_hello_job]
    schedules = [my_hourly_schedule]
    sensors = [make_slack_on_failure_sensor]
    return jobs + schedules + sensors
#sensors
Copy code
slack_on_failure_sensor.py

from dagster_slack.sensors import make_slack_on_run_failure_sensor
from dagster import RunFailureSensorContext,SensorDefinition

def my_message_fn(context: RunFailureSensorContext) -> str:
    return (
        f"Job {context.pipeline_run.pipeline_name} failed!"
        f"Error: {context.failure_event.message}"
    )

def make_slack_on_failure_sensor() -> SensorDefinition:
    return make_slack_on_run_failure_sensor(
        channel="dagster_test",
        slack_token="xoxb-3768110452066",
        text_fn= my_message_fn,
        dagit_base_url="<http://localhost:3000>",
    )
# OP
Copy code
hello.py

from dagster import op

@op
def fails():
    return Exception("failure!")
# JOB
Copy code
say_hello.py

from dagster import job
from ts_dagster.ops.hello import fails

@job
def say_hello_job():
    fails()
🤖 1
o

owen

08/03/2022, 4:33 PM
hi @junsik KIM! At a glance, the code looks correct to me. Do you have the dagster daemon running? This is required for sensor executions to fire.
j

junsik KIM

08/04/2022, 12:01 AM
dagster.daemon.SchedulerDaemon - WARNING - Could not load location ts_dagster to check for schedules due to the following error: dagster._core.errors.DagsterInvalidDefinitionError: Bad return value from repository construction function: all elements of list must be of type JobDefinition, GraphDefinition, PipelineDefinition, PartitionSetDefinition, ScheduleDefinition, SensorDefinition, AssetsDefinition, or SourceAsset.Got value of type <class ‘function’> at index 2.
error msg …..
o

owen

08/04/2022, 12:02 AM
ah I see now, it should be
Copy code
@repository
def ts_dagster():
    jobs = [say_hello_job]
    schedules = [my_hourly_schedule]
    sensors = [make_slack_on_failure_sensor()] # this line changed
    return jobs + schedules + sensors
(basically, you need to invoke the make_slack_on_failure_sensor function to get a sensor)
It doesn't seem necessary to wrap the make_slack_on_run_failure_sensor function in your own function, but it shouldn't hurt anything either. just thought I'd point that out
j

junsik KIM

08/04/2022, 12:08 AM
Where should I set the $DAGSTERHOME path when running the daemon?
error msg: UserWarning: No dagster instance configuration file (dagster.yaml) found at /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/dagster/ts_dagster. Defaulting to loading and storing all metadata with /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/dagster/ts_dagster. If this is the desired behavior, create an empty dagster.yaml file in /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/dagster/ts_dagster.
Copy code
dagster-daemon msg error
o

owen

08/04/2022, 12:19 AM
https://docs.dagster.io/deployment/dagster-instance walks though this in more detail, but the basic is that you should set $DAGSTER_HOME to wherever you want all the local data to be stored (often
~/.dagster
is a reasonable spot, but you might have other preferences). I believe your daemon should still function without setting that up (those are just warnings), but I could be wrong on that.
j

junsik KIM

08/04/2022, 12:33 AM
No slack messages on job failure. ㅜㅜㅜㅜㅜ
‘’’dagster--Lr5IqbU ❯ dagster-daemon run /Users/jskim/.local/share/virtualenvs/dagster--Lr5IqbU/lib/python3.9/site-packages/dagster/_core/instance/config.py37 UserWarning: No dagster instance configuration file (dagster.yaml) found at /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/test_daster/ts/dasterhome. Defaulting to loading and storing all metadata with /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/test_daster/ts/dasterhome. If this is the desired behavior, create an empty dagster.yaml file in /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/test_daster/ts/dasterhome. warnings.warn( 2022-08-04 092428 +0900 - dagster.daemon - INFO - instance is configured with the following daemons: [‘BackfillDaemon’, ‘SchedulerDaemon’, ‘SensorDaemon’] 2022-08-04 092428 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092528 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092629 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092728 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092829 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092928 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 093029 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 093132 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 093232 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 093332 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started.‘’'
'‘’ dagster--Lr5IqbU ❯ dagster-daemon run /Users/jskim/.local/share/virtualenvs/dagster--Lr5IqbU/lib/python3.9/site-packages/dagster/_core/instance/config.py37 UserWarning: No dagster instance configuration file (dagster.yaml) found at /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/test_daster/ts/dasterhome. Defaulting to loading and storing all metadata with /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/test_daster/ts/dasterhome. If this is the desired behavior, create an empty dagster.yaml file in /Users/jskim/Desktop/GSITM/AI_lab/99.workspace/GitLab/test_daster/ts/dasterhome. warnings.warn( 2022-08-04 092428 +0900 - dagster.daemon - INFO - instance is configured with the following daemons: [‘BackfillDaemon’, ‘SchedulerDaemon’, ‘SensorDaemon’] 2022-08-04 092428 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092528 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092629 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092728 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092829 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 092928 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 093029 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 093132 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 093232 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. 2022-08-04 093332 +0900 - dagster.daemon.SensorDaemon - INFO - Not checking for any runs since no sensors have been started. ‘’'
No slack messages on job failure. ㅜㅜㅜㅜㅜ
message has been deleted
message has been deleted
d

daniel

08/04/2022, 1:38 AM
Did you turn on the sensor in the Dagit UI?
j

junsik KIM

08/04/2022, 2:04 AM
It’s been resolved. It works normally. thank you
condagster 1
9 Views