Hi team! I need to write an `op` that will reload ...
# ask-community
d
Hi team! I need to write an
op
that will reload all of dagster’s definitions through the API. Does any one have an idea on how to do this? The idea here is to have my definitions reloaded after a dbt manifest changed.
t
Hmm, so I wouldn't recommend it through an Op, because that means Dagster would be trying to modify itself while it's running. What I'd recommend is triggering the GraphQL API to refresh the workspace when your manifest gets updated (ex. during the CD pipeline). Here's some sample code of how you can trigger it
d
@Tim Castillo, couldn’t I use
dagster_graphql.DagsterGraphQLClient
and call the
reload_repository_location
method? I’m doing something like this:
Copy code
@resource(config_schema={"GRAPHQL_ENDPOINT": StringSource})
def graphql_resource(context):
    """
    Resource used to create a graphql client.

    Required config resource:

    "graphql":{
        "config":{
            "GRAPHQL_ENDPOINT":{
                "env":"GRAPHQL_ENDPOINT"
            }
        }
    }

    """

    return DagsterGraphQLClient(hostname=context.resource_config["GRAPHQL_ENDPOINT"], use_https=True)

@op(required_resource_keys={"graphql"}, description="Reload repository definitions")
def reload_definitions(context):
    graphql_client = context.resources.graphql
    return graphql_client.reload_repository_location(
        repository_location_name="my-repo-name",
    )


@job(
    resource_defs={"graphql": graphql_resource},
    description="Reload repository definitions job",
    config={"resources": {"graphql": {"config": {"GRAPHQL_ENDPOINT": {"env": "GRAPHQL_ENDPOINT"}}}}},
)
def reload_definitions_job():
    reload_definitions()
But I’m getting the following error
t
Hmm, haven't tried from within an op because I didn't expect it to work. Though I feel like your error is more graphql-specific than Dagster specific. Rationale about why to trigger the reload outside of Dagster is because it's like swapping the engine of a car while driving it. When reloading, Dagster has to stop and rebuild itself, which might not work or cause some really funky behavior if you're triggering it from within Dagster.
What's your process like for building that dbt manifest?
d
yeah, this is the full error
I’m using
dbt_docs_generate_op
to generate the manifest, but that’s in a different job.
@Tim Castillo, any ideas on why I would be getting this “javascript not supported in your browser” error?
t
Ah, yeah, I believe the
DagsterGraphQLClient
isn't made to be used within Dagster, but supposed to be a wrapper around common queries that people run outside of Dagster.