Hello everyone.
What I worked on this week.
Implemented shelve in recording.py
This week I began working on an issue where I was trying to figure out the best way to approach tearing down APIs when the rest server stops working. For example, for the recording api, when the server shuts down, the recording api fires some code to write any references to videos to disk. There were a few issues to this:
1. The way to get this code to fire was very hack-ish. It relied on firing code when a kill signal was sent. Furthermore, this code was called from the recording api, and not from some more central location like the server.py class. If we had multiple apis that required some sort of teardown when the server shutdown, it would be better to have a more top down approach. Preferably something that flask provided.
2. There was really no default option provided by Flask to fire teardown code when the rest server shutdown. Since flask provided a number of teardown decorators (post-request teardowns etc.), but provided no teardown decorator that accomplished what I was trying to do, I figured that flask probably actively discouraged this style of teardown.
3. No references to recorded videos were written to disk until after the server shutdown. I was worried that if anything were to go wrong during the shutdown that this teardown code didn't fire, all information in our media dictionary would fail to persist. This was worrisome.
So I decided to make changes to the rest server and recording api so that no teardown code needed to be fired on shutdown of the REST server.
Instead of writing information to disk on shutdown of the REST server, I decided to use a persistent object library called "shelve". Basically you open a "shelve" object, and can treat it as a dictionary (with a few limitations) and when you want your changes to persist, you call sync() on the shelve object.
So, that works well, and no server shutdown teardown code is required for recording api to work properly anymore.
Implemented py.test fixtures in test_server.py
I had to make a number of changes to our REST server's tests so they would work with our changes, and I realized that since I was thinking about the testing framework, that it would be a good time to change our xunit style setup and teardown methods to py.test fixtures. So now test_server.py uses only py.test fixtures to create a baseline for our tests to run against.
Next week
Two things I'm thinking of all the time is the REST server's error framework, and authentication. So depending on when these changes I made this week get merged in, I will work on either of these. I will probably tackle authentication because I already have a lot of work stashed for implementing this. But I am always looking at ways that I could improve the error framework and will be noting things incrementally.
Until next week!
No comments:
Post a Comment