Skip to content

Update backend [part 4] - #29

Merged
vmarkovtsev merged 1 commit into
src-d:masterfrom
r0mainK:feature/backend
Jun 20, 2018
Merged

vmarkovtsev merged 1 commit into
src-d:masterfrom
r0mainK:feature/backend

Conversation

@r0mainK

@r0mainK r0mainK commented Jun 5, 2018

Copy link
Copy Markdown
Contributor

Take out unused methods in backend relating to the index, add initialize_backend method, create helper function in gcs_backend to avoid redundancy

@r0mainK r0mainK changed the title Update backend Update backend [part 4] Jun 5, 2018
@vmarkovtsev

Copy link
Copy Markdown
Collaborator

@r0mainK There are merge conflicts

@r0mainK

r0mainK commented Jun 15, 2018

Copy link
Copy Markdown
Contributor Author

@vmarkovtsev solved them, ready for review when you get the time

Comment thread modelforge/gcs_backend.py Outdated
client = self.create_client()
return client.lookup_bucket(self.bucket_name)

def initialize_backend(self, force):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior matches "reset" so better to rename

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread modelforge/gcs_backend.py Outdated
if blob.exists() and not force:
self._log.error("Model %s already exists, aborted.", meta["uuid"])
return 1
raise ExistingModelError

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to rename to ModelAlreadyExistsError

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread modelforge/gcs_backend.py Outdated
if isinstance(where, str):
os.makedirs(os.path.dirname(where), exist_ok=True)
f = open(where, "wb")
def fetch_model(self, source: str, file: str, chunk_size: int =DEFAULT_CHUNK_SIZE) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type hint for file is wrong, it is a union

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad, changing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also added typing to the rest of the file

Comment thread modelforge/gcs_backend.py
f = open(where, "wb")
def fetch_model(self, source: str, file: str, chunk_size: int =DEFAULT_CHUNK_SIZE) -> None:
self._log.info("Fetching %s...", source)
r = requests.get(source, stream=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check the http return code here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread modelforge/registry.py Outdated
except Exception as e:
log.critical("Failed to load the model: %s: %s" % (type(e).__name__, e))
return 1
model = GenericModel(source=path, dummy=True)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the error handlers? It is a top level function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here was my mistake, reverting

Comment thread modelforge/registry.py Outdated
model_url = backend.upload_model(path, base_meta, args.force)
except ModelExistsError:
return 1
model_url = backend.upload_model(path, base_meta, args.force)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I don't understand why, since the error is a custom one that clearly explains whats happening - and logs in upload_model also provide information. Unless you want to sytematically wrap errors this way to return 1 ? In which case we should wrap the other top level functions too, no ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyway reverting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep we should wrap everything, that was a dirty cutting off the edges

@r0mainK

r0mainK commented Jun 19, 2018

Copy link
Copy Markdown
Contributor Author

Added catches about everywhere, and moved the message to the logger in most cases. I put two TODO for when dulwich implements a porcelain error. Gonna add some test now, to get coverage a bit higher. But yeah ready for more review or merge after that.
I'm also gonna reorder the methods and functions so they are more coherent.

Signed-off-by: Romain Keramitas <r.keramitas@gmail.com>
Comment thread modelforge/registry.py
return 1

log.info("Deleting content of index ...")
backend.index.initialize_index()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future commit: rename initialize_index to reset

Comment thread modelforge/registry.py
log.info("Deleting content of index ...")
backend.index.initialize_index()
try:
backend.index.upload_index("initilialize", {})

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future commit: typo

Comment thread modelforge/registry.py
except ExistingBackendError:
return 1

log.info("Deleting content of index ...")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future commit: "Resetting the index"

Comment thread modelforge/registry.py
template_readme = backend.index.load_template(args.template_readme)
backend.index.update_readme(template_readme)
except ValueError:
return 1

@vmarkovtsev vmarkovtsev Jun 20, 2018 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are catching much code here, so better to split and log what has failed exactly.

The same is true for the rest of the return 1-s

Comment thread modelforge/registry.py
backend.index.update_readme(template_readme)
backend.index.upload_index("delete", meta)
try:
backend.index.upload_index("delete", meta)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future commit: rename to upload

@vmarkovtsev
vmarkovtsev merged commit d38fc1d into src-d:master Jun 20, 2018
@r0mainK
r0mainK deleted the feature/backend branch June 22, 2018 08:41
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

Successfully merging this pull request may close these issues.

2 participants