#23 Add database support and dummy Flask frontend
Merged by jkaluza. Opened by jkaluza.
jkaluza/freshmaker db-support  into  master

Download 23.patch

The schema is following:

sqlite> .schema events
CREATE TABLE events (
        id INTEGER NOT NULL, 
        message_id VARCHAR NOT NULL, 
        PRIMARY KEY (id)
);
sqlite> .schema artifact_builds
CREATE TABLE artifact_builds (
        id INTEGER NOT NULL, 
        name VARCHAR NOT NULL, 
        type INTEGER, 
        state INTEGER NOT NULL, 
        time_submitted DATETIME NOT NULL, 
        time_completed DATETIME, 
        dep_of_id INTEGER, 
        event_id INTEGER, 
        build_id INTEGER, 
        PRIMARY KEY (id), 
        FOREIGN KEY(dep_of_id) REFERENCES artifact_builds (id), 
        FOREIGN KEY(event_id) REFERENCES events (id)
);

How it could work:

  • When we submit new build X to some build system (Koji, MBS, ...) triggered by fedmsg event E, we will just add the Event to "events" table and build to "artifact_builds".
  • We will listen on message bus to find out whether the build X has finished successfully. If not, we will just update the build state in "artifact_builds" to failed.
  • If the build of X succeeds we will update the state to "done" and if there are other artifacts depending on this artifact, we will submit their builds to build system and create new rows in artifact_builds with event_id se to E and dep_of set to artifact X.

That way we can track what artifacts have been rebuilt as a result of particular event or particular artifact rebuid/update. We can also use this data to check for circular dependencies.

s/MBS/the app/

I only saw one cosmetic typo. Otherwise, :+1: from me.

When call

with make_session(conf) as session:
    ArtifactBuild.create(session, ...)

session.commit will be called twice. Would this be a problem when use SQLAlchemy?

And, if call session.commit in create, it would prevent from creating multiple ArtifactBuild at once.

I guess this command should be wrapped with console_script_help as well.

Duplicated.

It seems like you can drop this function and call manager.run() directly below.

Not sure about this. It seems like this is not being used anywhere. If you want to make flask-sqlalchemy automatically rollback the session if an exception happens, you probably need to do something like this:

@app.teardown_request
def teardown_request(exception):
if exception:
db.session.rollback()
db.session.remove()
db.session.remove()

at once

I meant in one transaction.

To be honest I have not checked this method deeply, it is copy-paste from the MBS code where we apparently use it in the poller thread which creates his own independent session. So far this is dead code for Freshmaker, so I'm going to remove this method.

rebased

Fixed the problems found during the review. Please re-review and I will ideally merge it :).

Pull-Request has been merged by jkaluza

Metadata