From 13b5d217d6476d038c8a3aae4f5454842901d7f7 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 10 Dec 2021 12:43:08 +0100 Subject: [PATCH 1/5] more info for more submitted emails --- cdci_data_analysis/analysis/email_helper.py | 15 +++++++++++++++ cdci_data_analysis/flask_app/templates/email.html | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/cdci_data_analysis/analysis/email_helper.py b/cdci_data_analysis/analysis/email_helper.py index 5e47f9cac..1e2dc2961 100644 --- a/cdci_data_analysis/analysis/email_helper.py +++ b/cdci_data_analysis/analysis/email_helper.py @@ -191,6 +191,20 @@ def send_email( # TODO: enable this sometimes # compressed_request_url = compress_request_url_params(request_url) + include_extra_message_submitted_status = False + if status == 'submitted': + # get all the number of already submitted emails in the directory + email_history_dirs_same_job_id = f"scratch_*_{job_id}*/email_history" + submitted_email_pattern = os.path.join( + email_history_dirs_same_job_id, + 'email_submitted_*.email' + ) + submitted_email_files = glob.glob(submitted_email_pattern) + logger.info("submitted_email_files: %s as %s", len(submitted_email_files), submitted_email_pattern) + # additional message for more submitted-status emails + if len(submitted_email_files) > 1: + include_extra_message_submitted_status = True; + if len(request_url) > 2000: possibly_compressed_request_url = "" permanent_url = False @@ -218,6 +232,7 @@ def send_email( 'instrument': instrument, 'product_type': product_type, 'time_request': time_request, + 'include_extra_message_submitted_status': include_extra_message_submitted_status, 'request_url': possibly_compressed_request_url, 'api_code_no_token': api_code_no_token, 'api_code': api_code, diff --git a/cdci_data_analysis/flask_app/templates/email.html b/cdci_data_analysis/flask_app/templates/email.html index b93994bb1..45b7a166f 100644 --- a/cdci_data_analysis/flask_app/templates/email.html +++ b/cdci_data_analysis/flask_app/templates/email.html @@ -14,6 +14,10 @@
{% if request.status == "submitted" %} Once products will be ready, you will receive a new email.
+{% if request.include_extra_message_submitted_status %} +This is not the first email of this type you receive, we are aware of it. +This is intended to update you regarding the status of the processing of your request. +{% endif %} {% elif request.status == "done" %} Your request is now ready.
{% elif request.status == "failed" %} From bc30e3c50932b9fde0ebae40516bd01f799ee896 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 10 Dec 2021 13:10:42 +0100 Subject: [PATCH 2/5] better var naming --- cdci_data_analysis/analysis/email_helper.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cdci_data_analysis/analysis/email_helper.py b/cdci_data_analysis/analysis/email_helper.py index 1e2dc2961..f6b4ea2c5 100644 --- a/cdci_data_analysis/analysis/email_helper.py +++ b/cdci_data_analysis/analysis/email_helper.py @@ -390,8 +390,8 @@ def is_email_to_send_run_query(logger, status, time_original_request, scratch_di time_last_email_submitted_sent = max(times) time_from_last_submitted_email = time_.time() - float(time_last_email_submitted_sent) - time_to_expiration = float(token_expiration_time) - time_.time() - interval_ok = time_from_last_submitted_email > min(time_to_expiration, email_sending_job_submitted_interval) + time_to_token_expiration = float(token_expiration_time) - time_.time() + interval_ok = time_from_last_submitted_email > min(time_to_token_expiration, email_sending_job_submitted_interval) logger.info("email_sending_job_submitted: %s", email_sending_job_submitted) logger.info("interval_ok: %s", interval_ok) From 1081d0344367ba3b8edf2d1576f7d1009dbbe81b Mon Sep 17 00:00:00 2001 From: burnout87 Date: Fri, 10 Dec 2021 14:46:02 +0100 Subject: [PATCH 3/5] intsub max --- cdci_data_analysis/analysis/email_helper.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cdci_data_analysis/analysis/email_helper.py b/cdci_data_analysis/analysis/email_helper.py index f6b4ea2c5..ca1c99ad7 100644 --- a/cdci_data_analysis/analysis/email_helper.py +++ b/cdci_data_analysis/analysis/email_helper.py @@ -366,6 +366,9 @@ def is_email_to_send_run_query(logger, status, time_original_request, scratch_di token_expiration_time = tokenHelper.get_token_expiration_time(decoded_token) logger.info("token_expiration_time: %s", token_expiration_time) + time_to_token_expiration = float(token_expiration_time) - time_.time() + + intsub = max(time_to_token_expiration, email_sending_job_submitted_interval) email_history_dir = os.path.join(scratch_dir + '/email_history') logger.info("email_history_dir: %s", email_history_dir) @@ -390,8 +393,8 @@ def is_email_to_send_run_query(logger, status, time_original_request, scratch_di time_last_email_submitted_sent = max(times) time_from_last_submitted_email = time_.time() - float(time_last_email_submitted_sent) - time_to_token_expiration = float(token_expiration_time) - time_.time() - interval_ok = time_from_last_submitted_email > min(time_to_token_expiration, email_sending_job_submitted_interval) + + interval_ok = time_from_last_submitted_email > intsub logger.info("email_sending_job_submitted: %s", email_sending_job_submitted) logger.info("interval_ok: %s", interval_ok) From 07f2b2116e283c54d0b4feae43bd2b935f1bf8e6 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Thu, 16 Dec 2021 17:05:08 +0100 Subject: [PATCH 4/5] test and template adaption --- cdci_data_analysis/flask_app/templates/email.html | 4 ++-- tests/reference_emails/submitted-dummy.html | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cdci_data_analysis/flask_app/templates/email.html b/cdci_data_analysis/flask_app/templates/email.html index 45b7a166f..23bb867bd 100644 --- a/cdci_data_analysis/flask_app/templates/email.html +++ b/cdci_data_analysis/flask_app/templates/email.html @@ -15,8 +15,8 @@ {% if request.status == "submitted" %} Once products will be ready, you will receive a new email.
{% if request.include_extra_message_submitted_status %} -This is not the first email of this type you receive, we are aware of it. -This is intended to update you regarding the status of the processing of your request. +This is not the first email of this type you receive, we are aware of it.
+This is intended to update you regarding the status of the processing of your request.
{% endif %} {% elif request.status == "done" %} Your request is now ready.
diff --git a/tests/reference_emails/submitted-dummy.html b/tests/reference_emails/submitted-dummy.html index a9747b5fb..eabe3b684 100644 --- a/tests/reference_emails/submitted-dummy.html +++ b/tests/reference_emails/submitted-dummy.html @@ -15,6 +15,7 @@ Once products will be ready, you will receive a new email.
+
You can inspect the status of your job using the following url.
From 308346724bce8c6a6385c28755d9918425bbd003 Mon Sep 17 00:00:00 2001 From: burnout87 Date: Thu, 16 Dec 2021 17:16:22 +0100 Subject: [PATCH 5/5] unclear templates adaption --- tests/reference_emails/submitted-no-api-code.html | 1 + .../reference_emails/submitted-numeric-not-very-long-dummy.html | 1 + .../submitted-numeric-not-very-long-no-api-code.html | 1 + .../submitted-numeric-not-very-long-numerical.html | 1 + tests/reference_emails/submitted-numeric-not-very-long.html | 1 + .../submitted-numeric-very-long-not-permanent.html | 1 + tests/reference_emails/submitted-numerical.html | 1 + 7 files changed, 7 insertions(+) diff --git a/tests/reference_emails/submitted-no-api-code.html b/tests/reference_emails/submitted-no-api-code.html index d0855772d..6452f6e8a 100644 --- a/tests/reference_emails/submitted-no-api-code.html +++ b/tests/reference_emails/submitted-no-api-code.html @@ -15,6 +15,7 @@ Once products will be ready, you will receive a new email.
+
You can retrieve the results by repeating the request. diff --git a/tests/reference_emails/submitted-numeric-not-very-long-dummy.html b/tests/reference_emails/submitted-numeric-not-very-long-dummy.html index a8be00495..ef9be5007 100644 --- a/tests/reference_emails/submitted-numeric-not-very-long-dummy.html +++ b/tests/reference_emails/submitted-numeric-not-very-long-dummy.html @@ -15,6 +15,7 @@ Once products will be ready, you will receive a new email.
+
You can inspect the status of your job using the following url.
diff --git a/tests/reference_emails/submitted-numeric-not-very-long-no-api-code.html b/tests/reference_emails/submitted-numeric-not-very-long-no-api-code.html index 4069efc6d..041701e13 100644 --- a/tests/reference_emails/submitted-numeric-not-very-long-no-api-code.html +++ b/tests/reference_emails/submitted-numeric-not-very-long-no-api-code.html @@ -15,6 +15,7 @@ Once products will be ready, you will receive a new email.
+
You can retrieve the results by repeating the request. diff --git a/tests/reference_emails/submitted-numeric-not-very-long-numerical.html b/tests/reference_emails/submitted-numeric-not-very-long-numerical.html index 8475c6457..3e7dcc78f 100644 --- a/tests/reference_emails/submitted-numeric-not-very-long-numerical.html +++ b/tests/reference_emails/submitted-numeric-not-very-long-numerical.html @@ -15,6 +15,7 @@ Once products will be ready, you will receive a new email.
+
You can inspect the status of your job using the following url.
diff --git a/tests/reference_emails/submitted-numeric-not-very-long.html b/tests/reference_emails/submitted-numeric-not-very-long.html index ea6b45610..1b5d66bb9 100644 --- a/tests/reference_emails/submitted-numeric-not-very-long.html +++ b/tests/reference_emails/submitted-numeric-not-very-long.html @@ -15,6 +15,7 @@ Once products will be ready, you will receive a new email.
+
You can inspect the status of your job using the following url.
diff --git a/tests/reference_emails/submitted-numeric-very-long-not-permanent.html b/tests/reference_emails/submitted-numeric-very-long-not-permanent.html index bc00ceb62..1f808baad 100644 --- a/tests/reference_emails/submitted-numeric-very-long-not-permanent.html +++ b/tests/reference_emails/submitted-numeric-very-long-not-permanent.html @@ -15,6 +15,7 @@ Once products will be ready, you will receive a new email.
+
You can inspect the status of your job using the following url.
diff --git a/tests/reference_emails/submitted-numerical.html b/tests/reference_emails/submitted-numerical.html index f3fa8df0c..b193227d3 100644 --- a/tests/reference_emails/submitted-numerical.html +++ b/tests/reference_emails/submitted-numerical.html @@ -15,6 +15,7 @@ Once products will be ready, you will receive a new email.
+
You can inspect the status of your job using the following url.