Skip to content

Commit

Permalink
Fix logging so we can see what happens in the remind case
Browse files Browse the repository at this point in the history
We check to see if a user has valid trips in the past 7 days before we send
them a reminder
(7034479).
However, all the related messages are displayed using `logging.debug`. Because
of the additional imports, logging is configured to WARNING, so they are never
displayed.

And in the case where there are no users with recent trips, this results in
insufficient logging to determine what happened.

- Changing the logging configuration location
- Changing the log level to INFO
- Bumping up some useful logs to INFO

Testing done:

Before the change

```
Found configuration, overriding...
Activating the environment...
Run trip labeling reminder...
Config file not found, returning a copy of the environment variables instead...
Retrieved config: {'DB_HOST': '...', 'DB_RESULT_LIMIT': None}
Connecting to database URL ...
WARNING:root:Push configured for app .... using platform firebase with token ... of length 152
```

After the change

```
Found configuration, overriding...
Activating the environment...
Run trip labeling reminder...
Config file not found, returning a copy of the environment variables instead...
Retrieved config: {'DB_HOST': '...', 'DB_RESULT_LIMIT': None}
Connecting to database URL ...
WARNING:root:Push configured for app ... using platform firebase with token ... of length 152
INFO:root:Successfully downloaded config with version 1 for Staging environment for testing programs only and data collection URL https://openpath-stage.nrel.gov/api/
INFO:root:No users to notify in lang en
```
  • Loading branch information
shankari committed Oct 6, 2024
1 parent e06895b commit acf6864
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bin/push/push_remind.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import arrow
import json
import logging
logging.basicConfig(level=logging.INFO)
import os
import requests
import sys
Expand Down Expand Up @@ -55,7 +56,6 @@ def bin_users_by_lang(uuid_list, langs, lang_key='phone_lang'):


if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
logging.debug(f"STUDY_CONFIG is {STUDY_CONFIG}")

STUDY_CONFIG = os.getenv('STUDY_CONFIG', "stage-study")
Expand All @@ -68,12 +68,12 @@ def bin_users_by_lang(uuid_list, langs, lang_key='phone_lang'):
sys.exit(1)

dynamic_config = json.loads(r.text)
logging.debug(f"Successfully downloaded config with version {dynamic_config['version']} "\
logging.info(f"Successfully downloaded config with version {dynamic_config['version']} "\
f"for {dynamic_config['intro']['translated_text']['en']['deployment_name']} "\
f"and data collection URL {dynamic_config['server']['connectUrl']}")

if "reminderSchemes" in dynamic_config:
logging.debug("Found flexible notification configuration, skipping server-side push")
logging.info("Found flexible notification configuration, skipping server-side push")
sys.exit(0)

# get push notification config (if not present in dynamic_config, use default)
Expand All @@ -99,9 +99,9 @@ def bin_users_by_lang(uuid_list, langs, lang_key='phone_lang'):
# for each language, send a push notification to the selected users in that language
for lang, uuids_to_notify in filtered_uuids_by_lang.items():
if len(uuids_to_notify) == 0:
logging.debug(f"No users to notify in lang {lang}")
logging.info(f"No users to notify in lang {lang}")
continue
logging.debug(f"Sending push notifications to {len(uuids_to_notify)} users in lang {lang}")
logging.info(f"Sending push notifications to {len(uuids_to_notify)} users in lang {lang}")
json_data = {
"title": push_config["title"][lang],
"message": push_config["message"][lang],
Expand Down

0 comments on commit acf6864

Please sign in to comment.