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
Add get_unit_status method #11
Conversation
This is looking good, @helrond. I have a few suggestions for consideration. With a few tweaks, I think that Regarding the error classes. It'd be interesting to adopt a proper/idiomatic class hierarchy of exceptions, e.g. Regarding the helper itself, should we try to leave AMClient as the low-level client interface focused on API communication? A helper like yours, that encapsulates some logic beyond simple API calls, could be part of the An additional idea which may not fit at all with your use case so please let me know, would provide a better experience for the user to focus on transfers only and hide the knowledge of how transfers transition into SIPs? The workflow could look as follows:
{
"uuid": "...",
"status": "...",
"name": "...",
"sip_uuid": "...",
"microservice": "...",
"directory": "...",
"path": "...",
"message": "...",
"type": "..."
} The helper knows how the transition from transfer to ingest happens, so it would hit
Calling the helper when the package made it into Ingest would result into two API calls, but I think that's acceptable. Also in AM 1.11 the cost associated to the database queries is lower because we added some indexes. Ultimately, the helper could take a |
Thanks @sevein - I've just pushed two commits which address your first two points (using I'm wondering if you have a reference you can point me to for the hierarchy of exceptions - I'm not totally following you there, but that's likely my lack of knowledge! I'm fine with moving the Regarding your last point: what you describe is basically how I had envisioned the function working, however my approach was to try the |
Looking good!
elasticsearch-py could be a good example because it's also based on urllib3/requests. Here's two examples outside the HTTP context: aiosmtplib.errors, celery.exceptions.
You're right. Let's leave it as part of AMClient, it would be an inconsistency otherwise.
I realize that you're perfectly solving the problem that you described. It seems useful if you don't know the type of your objects, but how often does that happen? I find myself frequently just waiting until a transfer becomes an AIP and reaches my AIP storage location. In that case, it's nice that something like the following:
Becomes:
|
OK, I've added some Exception which have a bit of a hierarchy. Definitely a rough draft, so open to suggestions:
Now that I've done this, I'm idly wondering, if we're going to the trouble of creating all these exceptions, why wouldn't we want to expose those to developers? I'm also still a little lost with your last suggestion. If I'm understanding correctly, your proposal would change
Is that what you're saying, or am I missing something here? If we're going this route then I think I can (and probably should) dispense with the exceptions and Last, I was hoping to write some tests for this. Can you give me any pointer for building the vcr.py cassettes? I see there are some credentials hardcoded into |
I was suggesting the hierarchy only for v2. It's a lot of work. I don't think we have to do that now. If we end up using _call_url in the new method that you're suggesting, I think it'd be just fine to leak python-request exceptions.
The code looks good. What's missing in _call_url_json is the ability to communicate errors precisely. What you're saying could be a good compromise though. But if I was using that helper I'd very much prefer to have access to the actual exceptions because they'll let me look up the response statuses. I've found that to be important, having implemented retries recently. E.g. I don't want my app to spend 10 minutes retrying on a 401 Unauthorized, but a 500 Internal Server Error is definitely worth retrying. I'd take that over consistency with other methods of AMClient.
Exactly. But you could just use mock, it'd make things simpler. You only have to patch a couple of methods after all. |
OK, I think we're getting closer. I've tweaked Last I've added some tests. I fully realize these tests are dumb, but I've never worked with Feedback/next steps welcome! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Thanks.
@helrond, I had a chance today to give this a try and it wasn't working for a couple of reasons. We forgot to pass the auth header and the base URL. Also when transitioning from transfer to ingest, we were not pulling the identifier of the SIP. I've pushed 389074e to your branch with some suggestions. Let me know what you think! |
Hi @sevein these changes look great, thank you! I also appreciate the improvements to the tests. I had not had a chance to actually test; was planning on doing that this week, so you beat me to it. |
Thanks @helrond. No rush, I'd still like to hear if this solution is working for you, since it's slightly different form what you were originally suggesting. |
Hi @sevein - I have been working on incorporating I still have some work to do, but as the diff shows, I was able to get rid of a pretty big chunk of code by using the |
That's awesome, thanks! |
@sevein at the risk of wearing out my welcome, any chance of getting this pushed up to PyPI? |
Totally! Ross plans to release the final v1 release soon. |
This hasn't been tested and is probably full of bugs but I wanted to see if you think I'm on the right track here. If so, my next moves will be to add logging, tests, and work on exception handling.
Connects to archivematica/Issues#972.