예제 #1
0
class Job(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    A single job, which is the actual execution unit for a build.
    """

    id = db.Column(GUID, primary_key=True, default=GUID.default_value)
    build_id = db.Column(GUID,
                         db.ForeignKey("build.id", ondelete="CASCADE"),
                         nullable=False,
                         index=True)
    number = db.Column(db.Integer, nullable=False)
    label = db.Column(db.String, nullable=True)
    status = db.Column(Enum(Status), nullable=False, default=Status.unknown)
    result = db.Column(Enum(Result), nullable=False, default=Result.unknown)
    allow_failure = db.Column(db.Boolean,
                              nullable=False,
                              default=False,
                              server_default="0")
    date_started = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    date_updated = db.Column(db.TIMESTAMP(timezone=True),
                             nullable=True,
                             onupdate=timezone.now)
    date_finished = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    data = db.Column(JSONEncodedDict, nullable=True)
    provider = db.Column(db.String, nullable=True)
    external_id = db.Column(db.String(64), nullable=True)
    url = db.Column(db.String, nullable=True)

    build = db.relationship("Build",
                            backref=db.backref("jobs",
                                               order_by="Job.date_created"),
                            innerjoin=True)
    stats = db.relationship(
        "ItemStat",
        foreign_keys="[ItemStat.item_id]",
        primaryjoin="ItemStat.item_id == Job.id",
        viewonly=True,
        uselist=True,
    )
    failures = db.relationship(
        "FailureReason",
        foreign_keys="[FailureReason.job_id]",
        primaryjoin="FailureReason.job_id == Job.id",
        viewonly=True,
        uselist=True,
    )

    __tablename__ = "job"
    __table_args__ = (
        db.UniqueConstraint("build_id", "number", name="unq_job_number"),
        db.UniqueConstraint("build_id",
                            "provider",
                            "external_id",
                            name="unq_job_provider"),
    )
    __repr__ = model_repr("build_id", "number", "status", "result")
예제 #2
0
파일: job.py 프로젝트: pombredanne/zeus
class Job(RepositoryBoundMixin, StandardAttributes, db.Model):
    """
    A single job, which is the actual execution unit for a build.
    """
    id = db.Column(GUID, primary_key=True, default=GUID.default_value)
    build_id = db.Column(GUID,
                         db.ForeignKey('build.id', ondelete='CASCADE'),
                         nullable=False,
                         index=True)
    number = db.Column(db.Integer, nullable=False)
    label = db.Column(db.String, nullable=True)
    status = db.Column(Enum(Status), nullable=False, default=Status.unknown)
    result = db.Column(Enum(Result), nullable=False, default=Result.unknown)
    date_started = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    date_finished = db.Column(db.TIMESTAMP(timezone=True), nullable=True)
    data = db.Column(JSONEncodedDict, nullable=True)
    provider = db.Column(db.String, nullable=True)
    external_id = db.Column(db.String(64), nullable=True)
    url = db.Column(db.String, nullable=True)

    build = db.relationship('Build',
                            backref=db.backref('jobs',
                                               order_by='Job.date_created'),
                            innerjoin=True)
    stats = db.relationship('ItemStat',
                            foreign_keys='[ItemStat.item_id]',
                            primaryjoin='ItemStat.item_id == Job.id',
                            viewonly=True,
                            uselist=True)
    failures = db.relationship(
        'FailureReason',
        foreign_keys='[FailureReason.job_id]',
        primaryjoin='FailureReason.job_id == Job.id',
        viewonly=True,
        uselist=True,
    )

    __tablename__ = 'job'
    __table_args__ = (db.UniqueConstraint('build_id',
                                          'number',
                                          name='unq_job_number'),
                      db.UniqueConstraint('build_id',
                                          'provider',
                                          'external_id',
                                          name='unq_job_provider'))
    __repr__ = model_repr('build_id', 'number', 'status', 'result')
예제 #3
0
class UserApiToken(StandardAttributes, db.Model, ApiTokenMixin):
    """
    An API token associated to users.
    """

    user_id = db.Column(GUID,
                        db.ForeignKey("user.id", ondelete="CASCADE"),
                        nullable=False,
                        unique=True)

    user = db.relationship("User",
                           backref=db.backref("tokens", uselist=False),
                           innerjoin=True)

    __tablename__ = "user_api_token"
    __repr__ = model_repr("user_id", "key")

    def get_token_key(self):
        return "u"
예제 #4
0
class UserApiToken(StandardAttributes, db.Model, ApiTokenMixin):
    """
    An API token associated to users.
    """

    user_id = db.Column(GUID,
                        db.ForeignKey('user.id', ondelete='CASCADE'),
                        nullable=False,
                        unique=True)

    user = db.relationship('User',
                           backref=db.backref('tokens', uselist=False),
                           innerjoin=True)

    __tablename__ = 'user_api_token'
    __repr__ = model_repr('user_id', 'key')

    def get_token_key(self):
        return 'u'

    def get_tenant(self):
        return self.user
예제 #5
0
class RepositoryApiToken(StandardAttributes, db.Model, ApiTokenMixin):
    """
    An API token associated to users.
    """

    repository_id = db.Column(
        GUID,
        db.ForeignKey("repository.id", ondelete="CASCADE"),
        nullable=False,
        unique=True,
    )

    repository = db.relationship("Repository",
                                 backref=db.backref("token", uselist=False),
                                 innerjoin=True)

    __tablename__ = "repository_api_token"
    __repr__ = model_repr("repository_id", "key")

    def get_token_key(self):
        return "r"

    def get_tenant(self):
        return self.user