Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

considers token expiration time for submitted email #312

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions cdci_data_analysis/analysis/email_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ def send_job_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
Expand Down Expand Up @@ -298,6 +312,7 @@ def send_job_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,
Expand Down Expand Up @@ -500,6 +515,12 @@ def is_email_to_send_run_query(logger, status, time_original_request, scratch_di
logger.info("email_sending_job_submitted_interval: %s", email_sending_job_submitted_interval)
log_additional_info_obj['email_sending_job_submitted_interval'] = f'{email_sending_job_submitted_interval}, {info_parameter}'

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)

Expand All @@ -523,8 +544,11 @@ def is_email_to_send_run_query(logger, status, time_original_request, scratch_di
times.append(float(f_name.split('_')[2]))

time_last_email_submitted_sent = max(times)
time_from_last_submitted_email = time_check - float(time_last_email_submitted_sent)
interval_ok = time_from_last_submitted_email > email_sending_job_submitted_interval

time_from_last_submitted_email = time_.time() - float(time_last_email_submitted_sent)

interval_ok = time_from_last_submitted_email > intsub


logger.info("interval_ok: %s", interval_ok)
log_additional_info_obj['interval_ok'] = interval_ok
Expand Down
4 changes: 4 additions & 0 deletions cdci_data_analysis/flask_app/templates/email.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<br>
{% if request.status == "submitted" %}
Once products will be ready, you will receive a new email.<br>
{% if request.include_extra_message_submitted_status %}
This is not the first email of this type you receive, we are aware of it.<br>
This is intended to update you regarding the status of the processing of your request.<br>
{% endif %}
{% elif request.status == "done" %}
Your request is now <b>ready</b>.<br>
{% elif request.status == "failed" %}
Expand Down
1 change: 1 addition & 0 deletions tests/reference_emails/submitted-dummy.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Once products will be ready, you will receive a new email.<br>


<br>

You can inspect the status of your job using the following <a href="PRODUCTS_URL?query_status=new&query_type=Real&instrument=empty-async&product_type=dummy">url</a>.<br>
Expand Down
1 change: 1 addition & 0 deletions tests/reference_emails/submitted-no-api-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Once products will be ready, you will receive a new email.<br>


<br>

You can retrieve the results by repeating the request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Once products will be ready, you will receive a new email.<br>


<br>

You can inspect the status of your job using the following <a href="PRODUCTS_URL?query_status=new&query_type=Real&instrument=empty-async&product_type=numerical&very_long_parameter_very_long_parameter_very_long_parameter_=unset">url</a>.<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Once products will be ready, you will receive a new email.<br>


<br>

You can retrieve the results by repeating the request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Once products will be ready, you will receive a new email.<br>


<br>

You can inspect the status of your job using the following <a href="PRODUCTS_URL?query_status=new&query_type=Real&instrument=empty-async&product_type=numerical&very_long_parameter_very_long_parameter_very_long_parameter_=unset">url</a>.<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Once products will be ready, you will receive a new email.<br>


<br>

You can inspect the status of your job using the following <a href="PRODUCTS_URL?query_status=new&query_type=Real&instrument=empty-async&product_type=numerical&very_long_parameter_very_long_parameter_very_long_parameter_=unset">url</a>.<br>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Once products will be ready, you will receive a new email.<br>


<br>

You can inspect the status of your job using the following <a href="PRODUCTS_URL/dispatch-data/resolve-job-url?job_id=1e2abe96307234f4&session_id=0T8G2BEDS3EBAHPX&token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJtdG1AbXRtY28ubmV0IiwibmFtZSI6Im1tZWhhcmdhIiwicm9sZXMiOiJnZW5lcmFsIiwiZXhwIjoxNjM3ODQyNzk4LCJ0ZW0iOjAsIm1zdG91dCI6dHJ1ZSwibXNzdWIiOnRydWUsImludHN1YiI6NX0.7v6uQFDHQ9vvYnPmBKMSTx5CTMQqa4lo4Gz7CuFJXQQ">url</a>.<br>
Expand Down
1 change: 1 addition & 0 deletions tests/reference_emails/submitted-numerical.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

Once products will be ready, you will receive a new email.<br>


<br>

You can inspect the status of your job using the following <a href="PRODUCTS_URL?query_status=new&query_type=Real&instrument=empty-async&product_type=dummy">url</a>.<br>
Expand Down