Skip to content

Commit

Permalink
This is the first deploy in series of deploys to give certain templat…
Browse files Browse the repository at this point in the history
…es priority in processing.

If the template is marked as priority the notification will be sent using the `notify` queue.
The `notify` queue is a low volume queue, messages here will not be queue behind a large job and should be delivered with in a more consistent time frame.

- Added templates.process_type and templates_history.process_type column.
- Added a template_process_type table to handle the enum for templates.process_type, initial values are normal and priority

https://www.pivotaltracker.com/story/show/135429147
  • Loading branch information
Rebecca Law committed Jan 13, 2017
1 parent d759842 commit 6c79ddb
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
20 changes: 19 additions & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ class NotificationStatistics(db.Model):
)


class TemplateProcessTypes(db.Model):
__tablename__ = 'template_process_type'
name = db.Column(db.String(255), primary_key=True)


SMS_TYPE = 'sms'
EMAIL_TYPE = 'email'
LETTER_TYPE = 'letter'
Expand All @@ -266,6 +271,10 @@ class NotificationStatistics(db.Model):

template_types = db.Enum(*TEMPLATE_TYPES, name='template_type')

NORMAL = 'normal'
PRIORITY = 'priority'
TEMPLATE_PROCESS_TYPE = [NORMAL, PRIORITY]


class Template(db.Model):
__tablename__ = 'templates'
Expand Down Expand Up @@ -293,6 +302,11 @@ class Template(db.Model):
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
created_by = db.relationship('User')
version = db.Column(db.Integer, default=1, nullable=False)
process_type = db.Column(db.String(255),
db.ForeignKey('template_process_type.name'),
index=True,
nullable=True,
default=NORMAL)

def get_link(self):
# TODO: use "/v2/" route once available
Expand Down Expand Up @@ -320,7 +334,11 @@ class TemplateHistory(db.Model):
created_by_id = db.Column(UUID(as_uuid=True), db.ForeignKey('users.id'), index=True, nullable=False)
created_by = db.relationship('User')
version = db.Column(db.Integer, primary_key=True, nullable=False)

process_type = db.Column(db.String(255),
db.ForeignKey('template_process_type.name'),
index=True,
nullable=True,
default=NORMAL)

MMG_PROVIDER = "mmg"
FIRETEXT_PROVIDER = "firetext"
Expand Down
38 changes: 38 additions & 0 deletions migrations/versions/0063_templates_process_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""empty message
Revision ID: 0063_templates_process_type
Revises: 0062_provider_details_history
Create Date: 2017-01-10 15:39:30.909308
"""

# revision identifiers, used by Alembic.
revision = '0063_templates_process_type'
down_revision = '0062_provider_details_history'

from alembic import op
import sqlalchemy as sa


def upgrade():
op.create_table('template_process_type',
sa.Column('name', sa.String(length=255), nullable=False),
sa.PrimaryKeyConstraint('name')
)
op.execute("INSERT INTO template_process_type VALUES ('normal'), ('priority')")
op.add_column('templates', sa.Column('process_type', sa.String(length=255), nullable=True))
op.create_index(op.f('ix_templates_process_type'), 'templates', ['process_type'], unique=False)
op.create_foreign_key('templates_history_process_type_fkey', 'templates', 'template_process_type', ['process_type'], ['name'])
op.add_column('templates_history', sa.Column('process_type', sa.String(length=255), nullable=True))
op.create_index(op.f('ix_templates_history_process_type'), 'templates_history', ['process_type'], unique=False)
op.create_foreign_key('templates_process_type_fkey', 'templates_history', 'template_process_type', ['process_type'], ['name'])


def downgrade():
op.drop_constraint('templates_history_process_type_fkey', 'templates_history', type_='foreignkey')
op.drop_index(op.f('ix_templates_history_process_type'), table_name='templates_history')
op.drop_column('templates_history', 'process_type')
op.drop_constraint('templates_process_type_fkey', 'templates', type_='foreignkey')
op.drop_index(op.f('ix_templates_process_type'), table_name='templates')
op.drop_column('templates', 'process_type')
op.drop_table('template_process_type')
1 change: 0 additions & 1 deletion tests/app/notifications/test_process_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from app.notifications.process_notifications import (create_content_for_notification,
persist_notification, send_notification_to_queue)
from app.v2.errors import BadRequestError
from tests.app.conftest import sample_notification, sample_template, sample_email_template


def test_create_content_for_notification_passes(sample_email_template):
Expand Down
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ def notify_db_session(notify_db):

notify_db.session.remove()
for tbl in reversed(notify_db.metadata.sorted_tables):
if tbl.name not in ["provider_details", "key_types", "branding_type", "job_status", "provider_details_history"]:
if tbl.name not in ["provider_details",
"key_types",
"branding_type",
"job_status",
"provider_details_history",
"template_process_type"]:
notify_db.engine.execute(tbl.delete())
notify_db.session.commit()

Expand Down

0 comments on commit 6c79ddb

Please sign in to comment.