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

Deividas Jodogalvis

02/28/2023, 8:16 PM
Hi, I have two docker jobs like this:
Copy code
@job
def dbt_transformed():
    docker_config = {
        "image": "dbt-image",
        "command": [
            "build",
            "--select",
            "tag:transformed",
        ]
    }
    docker_container_op.configured(
        docker_config,
        name="dbt_transformed_op",
    )()


@job
def dbt_transformed_other():
    docker_config = {
        "image": "dbt-image",
        "command": [
            "build",
            "--select",
            "tag:transformed_other",
        ]
    }
    docker_container_op.configured(
        docker_config,
        name="dbt_transformed_other_op",
    )()
They work, but the code is almost the same… Is there any way to do something like this?:
Copy code
job_config = {
   "dbt_transformed": "tag:transformed", 
   "dbt_transformed_other": "tag:transformed_other"
}

jobs = []

for job_name, select in job_config.items():
    docker_config = {
        "image": "dbt-image",
        "command": [
            "build",
            "--select",
            select,
        ]
    }
    op = docker_container_op.configured(
        docker_config,
        name=f"{job_name}_op",
    )
    job = define_job(name, op) # function that I miss
    jobs.append(job)
I can not find a function like
define_job
to accomplish what I need Any way to define jobs not with a decorator but with a function passing a name and an op ?
🤖 1
z

Zach

02/28/2023, 9:25 PM
You should be able to just define a simple factory function like this:
Copy code
job_config = {
   "dbt_transformed": "tag:transformed", 
   "dbt_transformed_other": "tag:transformed_other"
}

jobs = []

def define_job(job_name, select):
    @job(name=job_name)
    def job_template():
        docker_config = {
        "image": "dbt-image",
        "command": [
            "build",
            "--select",
            select,
        ]
        }
        op = docker_container_op.configured(
            docker_config,
            name=f"{job_name}_op",
        )
    return job_template

for job_name, select in job_config.items():
    job = define_job(name, select)
    jobs.append(job)
❤️ 1
d

Deividas Jodogalvis

03/01/2023, 5:57 AM
Thanks! That did the trick!
🎉 1
9 Views