mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-12 09:34:57 +08:00
Move ridad into an importable location and validate module state strings.
This commit is contained in:
2
rida.py
2
rida.py
@@ -123,7 +123,7 @@ def submit_build():
|
||||
build = rida.database.Build(module_id=module.id, package=pkgname, format="rpms")
|
||||
db.session.add(build)
|
||||
module.modulemd = mmd.dumps()
|
||||
module.state = "wait"
|
||||
module.state = rida.database.BUILD_STATES["init"]
|
||||
db.session.add(module)
|
||||
db.session.commit()
|
||||
# Publish to whatever bus we're configured to connect to.
|
||||
|
||||
@@ -24,11 +24,32 @@
|
||||
|
||||
"""Database handler functions."""
|
||||
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, create_engine
|
||||
from sqlalchemy.orm import sessionmaker, relationship
|
||||
from sqlalchemy import (
|
||||
Column,
|
||||
Integer,
|
||||
String,
|
||||
ForeignKey,
|
||||
create_engine,
|
||||
)
|
||||
from sqlalchemy.orm import (
|
||||
sessionmaker,
|
||||
relationship,
|
||||
validates,
|
||||
)
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
|
||||
|
||||
# Just like koji.BUILD_STATES, except our own codes for modules.
|
||||
BUILD_STATES = {
|
||||
"init": 0,
|
||||
"wait": 1,
|
||||
"build": 2,
|
||||
"done": 3,
|
||||
"failed": 4,
|
||||
"ready": 5,
|
||||
}
|
||||
|
||||
|
||||
class RidaBase(object):
|
||||
# TODO -- we can implement functionality here common to all our model
|
||||
# classes.
|
||||
@@ -77,10 +98,17 @@ class Module(Base):
|
||||
name = Column(String, nullable=False)
|
||||
version = Column(String, nullable=False)
|
||||
release = Column(String, nullable=False)
|
||||
# XXX: Consider making this a proper ENUM
|
||||
state = Column(String, nullable=False)
|
||||
state = Column(Integer, nullable=False)
|
||||
modulemd = Column(String, nullable=False)
|
||||
|
||||
@validates('state')
|
||||
def validate_state(self, key, field):
|
||||
if field in BUILD_STATES.values():
|
||||
return field
|
||||
if field in BUILD_STATES:
|
||||
return BUILD_STATES[field]
|
||||
raise ValueError("%s: %s, not in %r" % (key, field, BUILD_STATES))
|
||||
|
||||
def json(self):
|
||||
return {
|
||||
'id': self.id,
|
||||
|
||||
@@ -58,13 +58,12 @@ class Messaging(threading.Thread):
|
||||
for msg in rida.messaging.listen(backend=config.messaging):
|
||||
log.debug("Saw %r, %r" % (msg['msg_id'], msg['topic']))
|
||||
if '.buildsys.build.state.change' in msg['topic']:
|
||||
log.info("A build changed state in koji!!")
|
||||
self.handle_build_change(msg)
|
||||
elif '.rida.module.state.change' in msg['topic']:
|
||||
log.info("Our frontend says that a module changed state!!")
|
||||
self.handle_module_change(msg)
|
||||
else:
|
||||
pass
|
||||
|
||||
|
||||
class Polling(threading.Thread):
|
||||
def run(self):
|
||||
while True:
|
||||
@@ -77,7 +76,7 @@ class Polling(threading.Thread):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
logging.basicConfig(level=logging.DEBUG) # For now
|
||||
logging.info("Starting ridad.")
|
||||
try:
|
||||
Reference in New Issue
Block a user