You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to implement a small application that's going to hot reload its code from a remote repository. What it does is simple: every 5 minutes, it fetches the remote branch origin/main and updates the mymodule code to take the new version of the code into account in the running process.
Q1. How can I make jurigged take into account potentially new files once they're added to my remote git repository and fetched locally?
Q2. Is jurigged going to behave nicely if this runs in an asyncio loop? With a coroutine that fetches the latest git version every 5 minutes?
Thanks!
importpathlibimportgitimportjuriggedimportmymodulefromloguruimportloggerMYMODULE_DIR_PATH=pathlib.Path(mymodule.__path__[0]).parentifnot (MYMODULE_DIR_PATH/".git").is_dir():
raiseRuntimeError(f"could not find git repo in {MYMODULE_DIR_PATH}")
jurigged.watch(str(MYMODULE_DIR_PATH.absolute()))
MYMODULE_REPO=git.Repo(MYMODULE_DIR_PATH)
defupdate_code_from_git(branch: str="main") ->None:
cur_hash=MYMODULE_REPO.remotes.origin.refs[branch].commit.hexshalogger.info(
f"fetching origin/{branch} for repo mymodule. current hash is {cur_hash}"
)
MYMODULE_REPO.remotes.origin.fetch(branch)
new_hash=MYMODULE_REPO.remotes.origin.refs[branch].commit.hexshaifnew_hash!=cur_hash:
logger.info(
f"new hash {new_hash} found. code will be hard reset to origin/{branch}"" and hot reloaded"
)
MYMODULE_REPO.heads[branch].reset(
MYMODULE_REPO.remotes.origin.refs[branch], hard=True
)
else:
logger.info("hash did not change")
defmain():
# TODO: implementpassif__name__=="__main__":
main()
The text was updated successfully, but these errors were encountered:
I'm trying to implement a small application that's going to hot reload its code from a remote repository. What it does is simple: every 5 minutes, it fetches the remote branch
origin/main
and updates themymodule
code to take the new version of the code into account in the running process.Q1. How can I make
jurigged
take into account potentially new files once they're added to my remote git repository and fetched locally?Q2. Is
jurigged
going to behave nicely if this runs in an asyncio loop? With a coroutine that fetches the latest git version every 5 minutes?Thanks!
The text was updated successfully, but these errors were encountered: