| |
@@ -28,6 +28,10 @@
|
| |
from sqlalchemy.orm import (validates, relationship)
|
| |
|
| |
from freshmaker import db
|
| |
+ from freshmaker.events import (
|
| |
+ MBSModuleStateChangeEvent, GitModuleMetadataChangeEvent,
|
| |
+ GitRPMSpecChangeEvent, TestingEvent, GitDockerfileChangeEvent,
|
| |
+ BodhiUpdateCompleteStableEvent, KojiTaskStateChangeEvent)
|
| |
|
| |
# BUILD_STATES for the builds submitted by Freshmaker
|
| |
BUILD_STATES = {
|
| |
@@ -51,6 +55,18 @@
|
| |
|
| |
INVERSE_ARTIFACT_TYPES = {v: k for k, v in ARTIFACT_TYPES.items()}
|
| |
|
| |
+ EVENT_TYPES = {
|
| |
+ MBSModuleStateChangeEvent: 0,
|
| |
+ GitModuleMetadataChangeEvent: 1,
|
| |
+ GitRPMSpecChangeEvent: 2,
|
| |
+ TestingEvent: 3,
|
| |
+ GitDockerfileChangeEvent: 4,
|
| |
+ BodhiUpdateCompleteStableEvent: 5,
|
| |
+ KojiTaskStateChangeEvent: 6,
|
| |
+ }
|
| |
+
|
| |
+ INVERSE_EVENT_TYPES = {v: k for k, v in EVENT_TYPES.items()}
|
| |
+
|
| |
|
| |
class FreshmakerBase(db.Model):
|
| |
__abstract__ = True
|
| |
@@ -59,28 +75,43 @@
|
| |
class Event(FreshmakerBase):
|
| |
__tablename__ = "events"
|
| |
id = db.Column(db.Integer, primary_key=True)
|
| |
+ # ID of message generating the rebuild event.
|
| |
message_id = db.Column(db.String, nullable=False)
|
| |
+ # Searchable key for the event - used when searching for events from the JSON
|
| |
+ # API.
|
| |
+ search_key = db.Column(db.String, nullable=False)
|
| |
+ # Event type id defined in EVENT_TYPES - ID of class inherited from
|
| |
+ # BaseEvent class - used when searching for events of particular type.
|
| |
+ event_type_id = db.Column(db.Integer, nullable=False)
|
| |
|
| |
# List of builds associated with this Event.
|
| |
builds = relationship("ArtifactBuild", back_populates="event")
|
| |
|
| |
@classmethod
|
| |
- def create(cls, session, message_id):
|
| |
+ def create(cls, session, message_id, search_key, event_type):
|
| |
+ if event_type in EVENT_TYPES:
|
| |
+ event_type = EVENT_TYPES[event_type]
|
| |
event = cls(
|
| |
message_id=message_id,
|
| |
+ search_key=search_key,
|
| |
+ event_type_id=event_type
|
| |
)
|
| |
session.add(event)
|
| |
return event
|
| |
|
| |
@classmethod
|
| |
- def get_or_create(cls, session, message_id):
|
| |
+ def get_or_create(cls, session, message_id, search_key, event_type):
|
| |
instance = session.query(cls).filter_by(message_id=message_id).first()
|
| |
if instance:
|
| |
return instance
|
| |
- return cls.create(session, message_id)
|
| |
+ return cls.create(session, message_id, search_key, event_type)
|
| |
+
|
| |
+ @property
|
| |
+ def event_type(self):
|
| |
+ return INVERSE_EVENT_TYPES[self.event_type_id]
|
| |
|
| |
def __repr__(self):
|
| |
- return "<Event %s>" % (self.message_id)
|
| |
+ return "<Event %s, %r, %s>" % (self.message_id, self.event_type, self.search_key)
|
| |
|
| |
|
| |
class ArtifactBuild(FreshmakerBase):
|
| |
The main goal of this PR is to allow JSON API to query for events by type and by the
search_key
. It should be possible to do queries like this:In order to do these queries, we have to extend the Event table by Event type (so you can limit the query to just events triggered by Errata or MBS, or dist-git and so on) and add a key by which the events can be searched. The key is different per each event type. For dist-git, it is branch and commit hash, for MBS it is build ID and so on.
There is new
modules.EVENT_TYPES
list which gives each BaseEvent subclass database id. There is newBaseEvent.search_key
property, which returns the key used for searching for every BaseEvent instance.I'm not sure if the search_key is enough generally, but for the current events and other events I have in my mind currently it should be enough to just have single key to query on.