fix some issues uncovered during testing

This commit is contained in:
Kenneth Kehl
2023-05-01 13:26:19 -07:00
parent b16883e989
commit be04edd04a
7 changed files with 16 additions and 21 deletions

View File

@@ -42,6 +42,7 @@ from app.v2.errors import TooManyRequestsError
@notify_celery.task(name="process-job")
def process_job(job_id, sender_id=None):
current_app.logger.warning("ENTER process_job")
start = datetime.utcnow()
job = dao_get_job_by_id(job_id)
current_app.logger.info("Starting process-job task for job id {} with status: {}".format(job_id, job.job_status))
@@ -166,10 +167,10 @@ def __total_sending_limits_for_job_exceeded(service, job, job_id):
else:
return False
except TooManyRequestsError:
job.job_status = 'total sending limits exceeded'
job.job_status = 'sending limits exceeded'
job.processing_finished = datetime.utcnow()
dao_update_job(job)
current_app.logger.info(
current_app.logger.error(
"Job {} size {} error. Total sending limits {} exceeded".format(
job_id, job.notification_count, service.message_limit)
)

View File

@@ -436,7 +436,7 @@ class Service(db.Model, Versioned):
active = db.Column(db.Boolean, index=False, unique=False, nullable=False, default=True)
message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False)
# TODO nullable if we are adding it late?
total_message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=250000)
total_message_limit = db.Column(db.BigInteger, index=False, unique=False, nullable=False, default=7)
restricted = db.Column(db.Boolean, index=False, unique=False, nullable=False)
research_mode = db.Column(db.Boolean, index=False, unique=False, nullable=False, default=False)
email_from = db.Column(db.Text, index=False, unique=True, nullable=False)

View File

@@ -142,7 +142,7 @@ def persist_notification(
if key_type != KEY_TYPE_TEST and current_app.config['REDIS_ENABLED']:
current_app.logger.info('Redis enabled, querying cache key for service id: {}'.format(service.id))
cache_key = redis.daily_limit_cache_key(service.id)
total_key = redis.daily_total_cache_key()
total_key = redis.total_limit_cache_key(service.id)
current_app.logger.info('Redis daily limit cache key: {}'.format(cache_key))
if redis_store.get(cache_key) is None:
current_app.logger.info('Redis daily limit cache key does not exist')
@@ -163,7 +163,8 @@ def persist_notification(
else:
current_app.logger.info('Redis total limit cache key does exist')
redis_store.incr(total_key)
current_app.logger.info('Redis total limit cache key has been incremented')
current_app.logger.info(
f'Redis total limit cache key has been incremented to {redis_store.get(total_key)}')
current_app.logger.info(
"{} {} created at {}".format(notification_type, notification_id, notification_created_at)
)

View File

@@ -87,7 +87,7 @@ def check_service_over_total_message_limit(key_type, service):
redis_store.set(cache_key, service_stats, ex=86400)
return service_stats
if int(service_stats) >= service.total_message_limit:
current_app.logger.info(
current_app.logger.warning(
"service {} has been rate limited for total use sent {} limit {}".format(
service.id, int(service_stats), service.total_message_limit)
)

View File

@@ -1,3 +1,4 @@
from flask import current_app
from sqlalchemy.orm.exc import NoResultFound
from app.config import QueueNames