Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a notebook file is renamed or moved around it loses history #159

Open
marcinapostoluk opened this issue Sep 14, 2023 · 2 comments
Open

Comments

@marcinapostoluk
Copy link
Contributor

Old results are then showing separately from the new results. Might be good to provide a Move feature re-linking the old results to the modified report.

@marcinapostoluk
Copy link
Contributor Author

marcinapostoluk commented Sep 14, 2023

So far I moved my notebooks to folders semi-manually by running:

CAREFUL! need to run on same version of apscheduler as otherwise pickling results in incorrect data and scheduler will crash on startup

from ahl.mongo import PyMongoose
from ahl.mongo.auth import authenticate
from mkd.auth.mongo import get_auth
mongo = PyMongoose("[HOST]")._conn["[DB]"]
authenticate(mongo, "[USER]", "[PASS]")

from_path = "[old report path]"
to_path = "[new report path]"

modify paths

modified = []
lib = mongo["[lib]"]

for c in lib.find():
if c["report_name"] == from_path:
c["report_name"] = to_path
modified.append(c)
for m in modified:
lib.replace_one({"_id": m["_id"]}, m)

modify schedules

import pickle
modified = []
loaded = mongo["[lib]_scheduler"].find()
for l in loaded:
state = pickle.loads(l["job_state"])
if state["kwargs"]["report_name"] == from_path:
state["kwargs"]["report_name"] = to_path
print("replaced")
l["job_state"] = pickle.dumps(state)
modified.append(l)
for m in modified:
mongo["ahl_fts_scheduler"].replace_one({"_id": m["_id"]}, m)

@marcinapostoluk
Copy link
Contributor Author

Need also this to correct the schedules fully:

for c in lib.find():
if c['_id'] == old_path:
found = c

job_state = pickle.loads(found['job_state'])
job_state['kwargs']['scheduler_job_id'] = new_path
job_state['id'] = new_path
found['job_state'] = pickle.dumps(job_state)
found['_id'] = new_path
lib.save(found)
lib.delete_one({'_id': old_path})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant