Hi there,
I’m looking for the best way to store the results of the Publishing process into a database. I’d like to have a discussion about the best way of getting this accomplished and talk about the different pros and cons. that this approach might have. At the moment, I’m aiming to get it up and running using SQLite3.
Information to be stored
For the time being, this is the information that I want to store in the database:
- Name of the asset being published
- Name of the artist Publishing the asset
- Date of the Publish
- Project that the asset belongs to
- Information of the results of each plugin
In regards of that last point: It would be fairly simple to store the results as success / failure but ideally, I want to find a nice way to store the results of each plugin. One solution to this is to store the message of the exception raised if the plugin failed but I’m wondering if we can get fancier than that.
Let’s say that we have a validator that checks for a series of things and it is able to raise 3 different exceptions. I’m wondering if we could have a table in the database with those 3 exceptions and complete their values depending on which one gets raised when the plugin fails. Another instance in which this might be useful is if I want to store a list of items that are causing the issue because then I could use that list to look for matches within the database.
Starting Point
I think that a good starting point is the code that MarcusO posted on Gitter a while back (As some of the information written in the JSON file is relevant to what we want to put in the database):
import json
import pyblish.api
@pyblish.api.log
class PostValidator(pyblish.api.Validator):
order = pyblish.api.Validator.order + 0.5
families = ['*']
hosts = ['maya']
def process_context(self, context):
results = context.data("results")
self.log.info("Were there any errors?")
for result in results:
if result.get("error"):
path = r"Z:\results.json"
self.log.info("Yes there were, writing to: %s" % path)
with open(path, "w") as f:
return json.dump(results, f, indent=4, sort_keys=True)
self.log.info("No errors")
Database experience
I have to admit that I’m kind of new to the world of databases and I’m looking for advice. Hopefully, some of you have had experience with them.
I hope that we have have a good and healthy discussion about the best way to get this done though.
First things first
I guess that before I get cracking with code,it is important to define the following things:
- Structure of the database (Schema).
- The best way to retrieve information from plugins in preparation for the database.
Any advice that you might have is more than welcome.
Cheers,
Dave