batches.py: Don't pass SQLAlchemy objects between threads

SQLAlchemy objects can't be used from multiple threads - so when starting
threads for builds, pass the ComponentBuild id rather than the object.
(Note that despite the comment that the threads were sharing a session,
they weren't - what was passed to the thread was a scoped_session that
acts as a separate thread-local session per-thread.)

BUILD_COMPONENT_DB_SESSION_LOCK - a threading.Lock() object that was used
in a few places - but not nearly enough places to effectively lock usage
of a shared session - is removed.
This commit is contained in:
Owen W. Taylor
2020-11-09 11:56:38 -05:00
parent 4a3e6fb0fa
commit 5dcd63ebf9
4 changed files with 60 additions and 34 deletions

View File

@@ -1107,6 +1107,10 @@ class ComponentBuild(MBSBase):
Index("idx_component_builds_build_id_nvr", "module_id", "nvr", unique=True),
)
@classmethod
def from_id(cls, db_session, component_build_id):
return db_session.query(cls).filter(cls.id == component_build_id).first()
@classmethod
def from_component_event(cls, db_session, task_id, module_id=None):
_filter = db_session.query(cls).filter