update to correct error

This commit is contained in:
stvnrlly
2023-08-31 10:57:54 -04:00
parent bf33ed7173
commit 7bbb05059c
6 changed files with 20 additions and 16 deletions

View File

@@ -34,6 +34,7 @@ from app.notifications.validators import check_service_over_total_message_limit
from app.serialised_models import SerialisedService, SerialisedTemplate
from app.service.utils import service_allowed_to_send_to
from app.utils import DATETIME_FORMAT
from app.v2.errors import TotalRequestsError
@notify_celery.task(name="process-job")
@@ -153,16 +154,17 @@ def __total_sending_limits_for_job_exceeded(service, job, job_id):
try:
total_sent = check_service_over_total_message_limit(KEY_TYPE_NORMAL, service)
if total_sent + job.notification_count > service.total_message_limit:
raise TooManyRequestsError(service.total_message_limit)
raise TotalRequestsError(service.total_message_limit)
else:
return False
except TooManyRequestsError:
job.job_status = 'sending limits exceeded'
except TotalRequestsError:
job.job_status = "sending limits exceeded"
job.processing_finished = datetime.utcnow()
dao_update_job(job)
current_app.logger.error(
"Job {} size {} error. Total sending limits {} exceeded".format(
job_id, job.notification_count, service.message_limit)
job_id, job.notification_count, service.message_limit
)
)
return True

View File

@@ -487,7 +487,9 @@ class Service(db.Model, Versioned):
db.Boolean, index=False, unique=False, nullable=False, default=True
)
message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
total_message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
total_message_limit = db.Column(
db.BigInteger, index=False, unique=False, nullable=False
)
restricted = db.Column(db.Boolean, index=False, unique=False, nullable=False)
email_from = db.Column(db.Text, index=False, unique=True, nullable=False)
created_by_id = db.Column(

View File

@@ -81,7 +81,7 @@ def persist_notification(
reply_to_text=None,
billable_units=None,
document_download_count=None,
updated_at=None
updated_at=None,
):
current_app.logger.info("Persisting notification")

View File

@@ -46,7 +46,7 @@ def check_service_over_api_rate_limit(service, api_key):
def check_service_over_total_message_limit(key_type, service):
if key_type == KEY_TYPE_TEST or not current_app.config['REDIS_ENABLED']:
if key_type == KEY_TYPE_TEST or not current_app.config["REDIS_ENABLED"]:
return 0
cache_key = total_limit_cache_key(service.id)
@@ -59,9 +59,10 @@ def check_service_over_total_message_limit(key_type, service):
if int(service_stats) >= service.total_message_limit:
current_app.logger.warning(
"service {} has been rate limited for total use sent {} limit {}".format(
service.id, int(service_stats), service.total_message_limit)
service.id, int(service_stats), service.total_message_limit
)
)
raise TooManyRequestsError(service.total_message_limit)
raise TotalRequestsError(service.total_message_limit)
return int(service_stats)

View File

@@ -9,15 +9,15 @@ from alembic import op
import sqlalchemy as sa
revision = '0395_add_total_message_limit'
down_revision = '0394_remove_contact_list'
revision = "0395_add_total_message_limit"
down_revision = "0394_remove_contact_list"
def upgrade():
op.add_column('services', sa.Column('total_message_limit', sa.Integer))
op.add_column('services_history', sa.Column('total_message_limit', sa.Integer))
op.add_column("services", sa.Column("total_message_limit", sa.Integer))
op.add_column("services_history", sa.Column("total_message_limit", sa.Integer))
def downgrade():
op.drop_column('services', 'total_message_limit')
op.drop_column('services_history', 'total_message_limit')
op.drop_column("services", "total_message_limit")
op.drop_column("services_history", "total_message_limit")

View File

@@ -710,7 +710,6 @@ def test_update_service(client, notify_db_session, sample_service):
def test_cant_update_service_org_type_to_random_value(client, sample_service):
data = {
"name": "updated service name",
"email_from": "updated.service.name",