Hi everyone. Is there a way to re-execute the func...
# ask-community
e
Hi everyone. Is there a way to re-execute the function @repository? Code below:
Copy code
from dagster import repository, get_dagster_logger
my_logger = get_dagster_logger()

@repository
def my_repo():
    <http://my_logger.info|my_logger.info>("called")
    jobs = [...]
    schedules = [...]
    sensors = [...]

    return jobs + schedules + sensors
At startup, i see the "called" string in the console log. But if I click on
reload repository
from Dagit, it seems that the function
my_repo
is not being called (at least, no new "called" string in the log). Is this an expected behaviour? If yes, what the
reload repository
does?
j
Hmm yeah I would expect that to log again. Let me try to repro
Oh I missed that you’re using
get_dagster_logger()
. This emits events during a run, but is a no-op outside of a job. We could probably error instead
@Dagster Bot issue Raise error when using get_dagster_logger() outside of a job
d
e
Got it. But why the first time the log appear and the next times it doesn't?
j
Hmm for me it doesn’t appear either time
In any case it’s undefined behavior
e
The first time it appears, when the service starts (currently in a docker compose with code, daemon and dagit). But when i click on
reload
from dagit it doesn't.
I just want to know if the
relaod
in Dagit effectively re runs the function
my_repo
. Thanks.
j
It does
👍 1
e
Hi @johann, sorry for the insistence but i'm struggling with the @repository function. I think it's not being re-executed when i click on "Reload repository" on Dagit.
Copy code
from dagster import repository
from .my_graphs import graph
from random import randrange

load_jobs(id):
       return graph.to_job(name=f"Job_{id}")

@repository
def my_repo():
    jobs = load_jobs(randrange(10))
    schedules = [...]
    sensors = [...]

    return jobs + schedules + sensors
The first time the name of the job is, let's say,
Job_5
. I click on "Reload reposutory" but the name doesn't change. Is this an expected behaviour?
j
I can’t reproduce, the job name changes for me (on 0.15 at least). I did need to change your
load_jobs
fn to return a list
e
I'm using 0.14.5. I'll try later with 0.15. Maybe it has been fixed with the new versions!
That's strange. I tried with 0.15 and it doesn't seem to work neither. (fixed the missing list bug). I have my code repository, dagit and daemon in different containers (running everything on docker) and i use gRPC. Can be this connected to the problem?
d
Hey Emanuele - that's exactly what it is, this is a bit of a rough edge that we'd like to fix (making the Reload repository button actually do what you're expecting it to do and reload your code). It behaves differently when the code is running in a gRPC server since dagit doesn't have the ability currently to restart that server
👍 1
If you restart the container that's running your code though, dagit will automatically pick up the changes
e
Thank you Daniel, i was looking at the source code and i imagined something like this. I think i'll remove grpc, i don't need this feature and i prefer to re-execute the @repository function. In dev environment i restart the container as you said but i can't to do this in production. FYI: i use a rest API to configure dynamically the jobs, that's why i need this.