Add datetime of when a trigger was disabled

This commit is contained in:
Joseph Schorr 2017-10-24 14:20:01 -04:00 committed by Joseph Schorr
parent 93d79e777e
commit 3837a7c2ed
3 changed files with 31 additions and 0 deletions

View file

@ -711,6 +711,7 @@ class RepositoryBuildTrigger(BaseModel):
robot_null_delete=True)
enabled = BooleanField(default=True)
disabled_reason = EnumField(DisableReason, null=True)
disabled_datetime = DateTimeField(default=datetime.utcnow, null=True, index=True)
successive_failure_count = IntegerField(default=0)
successive_internal_error_count = IntegerField(default=0)

View file

@ -0,0 +1,28 @@
"""Add disabled datetime to trigger
Revision ID: 87fbbc224f10
Revises: 17aff2e1354e
Create Date: 2017-10-24 14:06:37.658705
"""
# revision identifiers, used by Alembic.
revision = '87fbbc224f10'
down_revision = '17aff2e1354e'
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
def upgrade(tables):
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('repositorybuildtrigger', sa.Column('disabled_datetime', sa.DateTime(), nullable=True))
op.create_index('repositorybuildtrigger_disabled_datetime', 'repositorybuildtrigger', ['disabled_datetime'], unique=False)
# ### end Alembic commands ###
def downgrade(tables):
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index('repositorybuildtrigger_disabled_datetime', table_name='repositorybuildtrigger')
op.drop_column('repositorybuildtrigger', 'disabled_datetime')
# ### end Alembic commands ###

View file

@ -295,10 +295,12 @@ def update_trigger_disable_status(trigger, final_phase):
error_threshold = config.app_config.get('SUCCESSIVE_TRIGGER_INTERNAL_ERROR_DISABLE_THRESHOLD')
if failure_threshold and trigger.successive_failure_count >= failure_threshold:
trigger.disabled_datetime = datetime.utcnow()
trigger.enabled = False
trigger.disabled_reason = RepositoryBuildTrigger.disabled_reason.get_id('successive_build_failures')
elif (error_threshold and
trigger.successive_internal_error_count >= error_threshold):
trigger.disabled_datetime = datetime.utcnow()
trigger.enabled = False
trigger.disabled_reason = RepositoryBuildTrigger.disabled_reason.get_id('successive_build_internal_errors')