I want to make an `@whatnot_job` decorator that me...
# dagster-feedback
s
I want to make an
@whatnot_job
decorator that merges in default config into job definitions. Has anyone done this before? I am having some difficulty getting the args to pass correctly. What I want is something like this -- anyone
Copy code
def whatnot_job(func, **kwargs):
    # merge default tags with passed in tags
    default_tags = {"foo": "bar"}
    kwargs["tags"] = kwargs.get("tags", {}).update(default_tags)

    # create a job by passing in updated kwargs to @job decorator
    @job(**kwargs)
    def my_job():
        return func

    return my_job
anyone have ideas on how to do this? also, not sure if #dagster-feedback is the right place for these "best practices" type of questions?
It's similar to what @Binoy Shah mentions here. Not sure if you got something built for the @heavyjob? https://dagster.slack.com/archives/C014N0PK37E/p1654550563253299
i think the Factory pattern would always generate the same op/job pattern?
m
I recently made an
@op
wrapper: https://dagster.slack.com/archives/C01U954MEER/p1650473204641889 , may have some similarities in how you'd implement it.
🔥 2
s
amazing @Mark Fickett , this is exactly what i want
j
Mark beat me to the punch, but I had
Copy code
def whatnot_job(*args, **kwargs):
    default_tags = {"foo": "bar"}
    kwargs["tags"] = {**kwargs.get("tags", {}), **default_tags}

    def inner(func):
        return (job(*args, **kwargs))(func)

    return inner


@whatnot_job()
def johann_whatnot_job():
    pass
(which I have only cursorily tested)
🎉 1
@Dagster Bot docs Custom job and op decorators
🎉 2
d
s
@johann this is perfect 🎉