Hi, I have a scheduled job and I am trying to use ...
# ask-community
s
Hi, I have a scheduled job and I am trying to use Slack to send notifications whenever any operations failed within a job for any schedules. Here are the codes:
Copy code
@slack_on_failure("#{channel}".format(channel=os.getenv("SLACK_CHANNEL")), dagit_base_url=os.getenv("DAGIT_BASE_URL"))
@job(resource_defs={"scheduled_date": make_values_resource(), 'slack': slack_resource}, op_retry_policy=default_policy)
def my_job():
   ...

@schedule(job=direct_mail_job, cron_schedule="0 0 * * *" , execution_timezone="US/Eastern")
def direct_mail_job_schedule(context: ScheduleEvaluationContext):
    scheduled_date = context.scheduled_execution_time.strftime("%Y-%m-%d")
    return RunRequest(
        run_config={"resources": {"scheduled_date": {"config":  scheduled_date,}, 'slack': {'config': {'token': os.getenv('SLACK_TOKEN')}}}}
    )
It is working fine when I run in my local using launchpad. For some reason, when the job ran on a schedule in ECS, it failed with the following error. I have an environment variable
SLACK_TOKEN
configured.
Copy code
dagster._core.errors.DagsterInvalidConfigError: Error in config for job
    Error 1: Value at path root:resources:slack:config:token must not be None. Expected "(String | { env: String })"
  File "/usr/local/lib/python3.9/site-packages/dagster/_grpc/impl.py", line 498, in get_external_execution_plan_snapshot
    create_execution_plan(
  File "/usr/local/lib/python3.9/site-packages/dagster/_core/execution/api.py", line 958, in create_execution_plan
    resolved_run_config = ResolvedRunConfig.build(pipeline_def, run_config, mode=mode)
  File "/usr/local/lib/python3.9/site-packages/dagster/_core/system_config/objects.py", line 166, in build
    raise DagsterInvalidConfigError(
second question, since this schedule, the job failed to run, it shows 'Failure' for this schedule (see screenshot below). How can I re-run this schedule if I fix the job?
d
Hi Sean - the error you're seeing here is consistent with the SLACK_TOKEN env var not available in your gRPC / user code server - i would recommend double-checking that it's actually being set there (it needs to be set in the task/process that's running the code, not dagit or the daemon)
We don't currently have a way to re-run schedules unfortunately, but if your job is partitioned you can run a backfill, or you can launch runs from the Launchpad with the same config that they would have run from the schedule
s
Thanks, @daniel let me test it out.
@daniel it is working now, thanks for your help.
are there any documents regarding to which kind of the environment variables need to be available in user code server? some of the environment variables that I put in daemon server, and my jobs are working fine, except this one.
d
A good rule of thumb is if they're accessed as part of your code, they need to be in the user code container (dagit and the daemon never load your code directly, so they don't need env vars that are only referenced in your code - but the user code container does load your code, so it does need them)