Skip to content

Commit

Permalink
get notification count faster (#2133)
Browse files Browse the repository at this point in the history
  • Loading branch information
sastels authored Mar 7, 2024
1 parent 2564504 commit 4c0ce9a
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions app/job/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def get_jobs_by_service(service_id):
@job_blueprint.route("", methods=["POST"])
def create_job(service_id):
service = dao_fetch_service_by_id(service_id)
current_app.logger.info(" TEMP LOGGING 1: done dao_fetch_service_by_id")
if not service.active:
raise InvalidRequest("Create job is not allowed: service is inactive ", 403)

Expand All @@ -147,29 +146,25 @@ def create_job(service_id):
data.update(**get_job_metadata_from_s3(service_id, data["id"]))
except KeyError:
raise InvalidRequest({"id": ["Missing data for required field."]}, status_code=400)
current_app.logger.info(" TEMP LOGGING 2: done data.update")

if data.get("valid") != "True":
raise InvalidRequest("File is not valid, can't create job", 400)

data["template"] = data.pop("template_id")

template = dao_get_template_by_id(data["template"])
current_app.logger.info(" TEMP LOGGING 3: done dao_get_template_by_id")
template_errors = unarchived_template_schema.validate({"archived": template.archived})

if template_errors:
raise InvalidRequest(template_errors, status_code=400)

job = get_job_from_s3(service_id, data["id"])
current_app.logger.info(" TEMP LOGGING 4: done get_job_from_s3")
recipient_csv = RecipientCSV(
job,
template_type=template.template_type,
placeholders=template._as_utils_template().placeholders,
template=Template(template.__dict__),
)
current_app.logger.info(" TEMP LOGGING 5: done RecipientCSV()")

if template.template_type == SMS_TYPE:
# calculate the number of simulated recipients
Expand All @@ -187,14 +182,13 @@ def create_job(service_id):
increment_sms_daily_count_send_warnings_if_needed(service, len(recipient_csv))

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

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))
current_app.logger.info(" TEMP LOGGING 6: done checking limits")
increment_email_daily_count_send_warnings_if_needed(service, notification_count)

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

Expand All @@ -204,11 +198,9 @@ def create_job(service_id):
job.job_status = JOB_STATUS_SCHEDULED

dao_create_job(job)
current_app.logger.info(" TEMP LOGGING 7: done dao_create_job")

if job.job_status == JOB_STATUS_PENDING:
process_job.apply_async([str(job.id)], queue=QueueNames.JOBS)
current_app.logger.info(" TEMP LOGGING 8: done process_job.apply_async")

job_json = job_schema.dump(job)
job_json["statistics"] = []
Expand Down

0 comments on commit 4c0ce9a

Please sign in to comment.