Hi folks I want to understand if there is anyway I...
# ask-community
v
Hi folks I want to understand if there is anyway I can configure jobs dynamically in dagster. The config is in a DB.
Copy code
@schedule( 
     cron_schedule="0 9 * * 1-5", 
     job=dp_job, 
     execution_timezone="Europe/Stockholm", 
 ) 
 def dp_job_run(context):      return {"ops": {"daily_dag": {"config": {"table": 'a'}}}}
This is what I have. Now I want something like this.
Copy code
@schedule( 
     cron_schedule="0 9 * * 1-5", 
     job=dp_job, 
     execution_timezone="Europe/Stockholm", 
 ) 
 def dp_job_run(context): 
    Tables=['a','b']
    # want to do something like this
    for i in Tables:
        yield {"ops": {"daily_dag": {"config": {"table": i}}}}
Though yield does not work. But I hope this gets across what I need. I have already defined the ops and jobs in other files. I want to create unique jobs for every table name.
🤖 1
j
Have you tried modifying the code to yield a
RunRequest
object? It looks like you are yielding the config dictionary itself, but I don't think that is sufficient to get your job to run, even if you are pointing the schedule to the job in the decorator.
v
@Justin Taylor I could do that and try. Would it be better to use repositories instead of this approach?
j
I'm not seeing the connection between a Dagster
repository
and this problem. Can you elaborate? You will need to reference this schedule within your
Definitions
call, or
repository
, if that is the construct you are using.
v
I am fairly new to dagster. I think I misunderstood how
repository
works. WIll try your approach on using the RunRequest object.
j
Hey @Varun P ! @Justin Taylor is correct, yielding a RunRequest should solve your problem here. If you’d like to reference a code example, here’s one https://docs.dagster.io/concepts/partitions-schedules-sensors/schedules#schedules-that-provide-custom-run-config-and-tags rather then `return`ing a single
RunRequest
, you would
yield
a
RunRequest
for each config you get from the database
v
Thank you