Commit Diff
5 files changed
+46 -1
652d9f5 .. ab9360b

@@ -0,0 +1,24 @@

+ """Add blocked_by column for batch

+ 

+ Revision ID: 8ae65946df53

+ Revises: b64659389c54

+ Create Date: 2019-03-27 18:38:03.758974

+ 

+ """

+ 

+ # revision identifiers, used by Alembic.

+ revision = '8ae65946df53'

+ down_revision = 'b64659389c54'

+ 

+ from alembic import op

+ import sqlalchemy as sa

+ 

+ 

+ def upgrade():

+     op.add_column('batch', sa.Column('blocked_by_id', sa.Integer(), nullable=True))

+     op.create_foreign_key('batch_blocked_by_id_fkey', 'batch', 'batch', ['blocked_by_id'], ['id'])

+ 

+ 

+ def downgrade():

+     op.drop_constraint('batch_blocked_by_id_fkey', 'batch', type_='foreignkey')

+     op.drop_column('batch', 'blocked_by_id')

@@ -1103,6 +1103,15 @@

      def filter_by_package_name(cls, query, package_name):

          return query.join(models.Package).filter(models.Package.name == package_name)

  

+     @classmethod

+     def filter_not_blocked_batches(cls, builds):

+         filtered = []

+         for build in builds:

+             if build.batch and build.batch.blocked_by and not build.batch.blocked_by.finished:

+                 continue

+             filtered.append(build)

+         return filtered

+ 

  

  class BuildChrootsLogic(object):

      @classmethod

@@ -111,8 +111,10 @@

          return [batches[number] for number in sorted(batches.keys())]

  

      def add_builds(self, rpms, module):

+         blocked_by_id = None

          for group in self.get_build_batches(rpms):

              batch = models.Batch()

+             batch.blocked_by_id = blocked_by_id

              db.session.add(batch)

              for pkgname, rpm in group.items():

                  clone_url = self.get_clone_url(pkgname, rpm)

@@ -123,6 +125,9 @@

                  build.module_id = module.id

                  db.session.add(build)

  

+             # Every batch needs to by blocked by the previous one

+             blocked_by_id = batch.id

+ 

      def get_clone_url(self, pkgname, rpm):

          if rpm.get_repository():

              return rpm.get_repository()

@@ -1332,6 +1332,12 @@

  

  class Batch(db.Model):

      id = db.Column(db.Integer, primary_key=True)

+     blocked_by_id = db.Column(db.Integer, db.ForeignKey("batch.id"), nullable=True)

+     blocked_by = db.relationship("Batch", remote_side=[id])

+ 

+     @property

+     def finished(self):

+         return all([b.finished for b in self.builds])

  

  

  class Module(db.Model, helpers.Serializer):

@@ -183,8 +183,9 @@

      """

      Return the job queue.

      """

+     srpm_tasks = BuildsLogic.filter_not_blocked_batches(BuildsLogic.get_pending_srpm_build_tasks())

      build_records = ([get_build_record(task) for task in BuildsLogic.get_pending_build_tasks()] +

-                      [get_srpm_build_record(task) for task in BuildsLogic.get_pending_srpm_build_tasks()])

+                      [get_srpm_build_record(task) for task in srpm_tasks])

      log.info('Selected build records: {}'.format(build_records))

      return flask.jsonify(build_records)