mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-21 07:51:13 -05:00
Add jobs.notifications_delivered and jobs.notifications_failed counts to the jobs table.
This commit is contained in:
@@ -258,6 +258,9 @@ class Job(db.Model):
|
||||
status = db.Column(db.Enum(*JOB_STATUS_TYPES, name='job_status_types'), nullable=False, default='pending')
|
||||
notification_count = db.Column(db.Integer, nullable=False)
|
||||
notifications_sent = db.Column(db.Integer, nullable=False, default=0)
|
||||
notifications_delivered = db.Column(db.Integer, nullable=False, default=0)
|
||||
notifications_failed = db.Column(db.Integer, nullable=False, default=0)
|
||||
|
||||
processing_started = db.Column(
|
||||
db.DateTime,
|
||||
index=False,
|
||||
|
||||
48
migrations/versions/0021_add_delivered_failed_counts.py
Normal file
48
migrations/versions/0021_add_delivered_failed_counts.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""empty message
|
||||
|
||||
Revision ID: 0021_add_delivered_failed_counts
|
||||
Revises: 0020_template_history_fix
|
||||
Create Date: 2016-05-23 15:05:25.109346
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '0021_add_delivered_failed_counts'
|
||||
down_revision = '0020_template_history_fix'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column('jobs', sa.Column('notifications_delivered', sa.Integer(), nullable=True))
|
||||
op.add_column('jobs', sa.Column('notifications_failed', sa.Integer(), nullable=True))
|
||||
conn = op.get_bind()
|
||||
results = conn.execute("select distinct job_id from notifications")
|
||||
res = results.fetchall()
|
||||
|
||||
for x in res:
|
||||
if x.job_id:
|
||||
op.execute("update jobs set notifications_delivered = ("
|
||||
"select count(status) from notifications where status = 'delivered' and job_id = '{}' "
|
||||
"group by status, job_id)"
|
||||
"where jobs.id = '{}'".format(x.job_id, x.job_id))
|
||||
|
||||
op.execute("update jobs set notifications_failed = ("
|
||||
"select count(status) from notifications "
|
||||
"where status in ('failed','technical-failure', 'temporary-failure', 'permanent-failure') "
|
||||
"and job_id = '{}' group by status, job_id)"
|
||||
"where jobs.id = '{}'".format(x.job_id, x.job_id))
|
||||
op.execute("update jobs set notifications_delivered = 0 where notifications_delivered is null")
|
||||
op.execute("update jobs set notifications_failed = 0 where notifications_failed is null")
|
||||
op.alter_column('jobs', 'notifications_delivered', nullable=False)
|
||||
op.alter_column('jobs', 'notifications_failed', nullable=False)
|
||||
### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_column('jobs', 'notifications_failed')
|
||||
op.drop_column('jobs', 'notifications_delivered')
|
||||
### end Alembic commands ###
|
||||
@@ -31,6 +31,8 @@ def test_create_job(sample_template):
|
||||
assert Job.query.count() == 1
|
||||
job_from_db = Job.query.get(job_id)
|
||||
assert job == job_from_db
|
||||
assert job_from_db.notifications_delivered == 0
|
||||
assert job_from_db.notifications_failed == 0
|
||||
|
||||
|
||||
def test_get_job_by_id(sample_job):
|
||||
|
||||
Reference in New Issue
Block a user