Hey everyone, is there a way to run a scheduled jo...
# ask-community
j
Hey everyone, is there a way to run a scheduled job right after dagster was started/on startup? i wrote a sensor that runs every 30 sec and the job this sensor executes depends on the output of a scheduled job (every hour). The scheduled job generates/updates a table that contains foreign keys for a table the sensor job updates.
Copy code
def generate_hourly_cron_schedule():
    # schedule should start after dagster is started, so generate a cronjob taking current minute into account
    now = datetime.datetime.now()
    minute = now.minute+1

    cron_schedule = f"{minute} * * * *"

    return cron_schedule
o
hi @jstet! is that working for you? I'd expect some strangeness involved with that schedule as the scheduler daemon periodically reloads itself (and therefore the minute would be updated periodically). one thing to figure out here is exactly what "on startup" means in your case -- is this basically you have something that you want to automatically happen whenever you run
dagster dev
? it seems like the basic behavior you're looking for is "run once an hour, starting from when the dagster dev process was initiated", is that accurate? A more stable version of that than your above code might just be to do something like
Copy code
STARTUP_MINUTE=$(date +"%M") dagster dev -f ...
then use os.getenv("STARTUP_MINUTE") inside your schedule code
basically, dagster doesn't keep track of when it was started, so you'd probably want to feed that in manually, and this is a fairly simple way of doing so