Skip to content

Commit

Permalink
get notification count faster
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels committed Mar 6, 2024
1 parent b33730a commit b23cf4f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/job/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,31 +169,32 @@ def create_job(service_id):
placeholders=template._as_utils_template().placeholders,
template=Template(template.__dict__),
)
notification_count = int(data.get("notification_count", len(recipient_csv)))
current_app.logger.info(" TEMP LOGGING 5: done RecipientCSV()")

if template.template_type == SMS_TYPE:
# calculate the number of simulated recipients
numberOfSimulated = sum(simulated_recipient(i["phone_number"].data, template.template_type) for i in recipient_csv.rows)
mixedRecipients = numberOfSimulated > 0 and numberOfSimulated != len(recipient_csv)
mixedRecipients = numberOfSimulated > 0 and numberOfSimulated != notification_count

# if they have specified testing and NON-testing recipients, raise an error
if mixedRecipients:
raise InvalidRequest(message="Bulk sending to testing and non-testing numbers is not supported", status_code=400)

is_test_notification = len(recipient_csv) == numberOfSimulated
is_test_notification = notification_count == numberOfSimulated

if not is_test_notification:
check_sms_daily_limit(service, len(recipient_csv))
increment_sms_daily_count_send_warnings_if_needed(service, len(recipient_csv))
check_sms_daily_limit(service, notification_count)
increment_sms_daily_count_send_warnings_if_needed(service, notification_count)

elif template.template_type == EMAIL_TYPE:
check_email_daily_limit(service, len(recipient_csv))
check_email_daily_limit(service, notification_count)
current_app.logger.info(" TEMP LOGGING 6a: done check_email_daily_limit")

scheduled_for = datetime.fromisoformat(data.get("scheduled_for")) if data.get("scheduled_for") else None

if scheduled_for is None or not scheduled_for.date() > datetime.today().date():
increment_email_daily_count_send_warnings_if_needed(service, len(recipient_csv))
increment_email_daily_count_send_warnings_if_needed(service, notification_count)
current_app.logger.info(" TEMP LOGGING 6: done checking limits")

data.update({"template_version": template.version})
Expand Down

0 comments on commit b23cf4f

Please sign in to comment.