Skip to content

Commit 3171378

Browse files
committed
add type hints and better docstrings
1 parent e5aa575 commit 3171378

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

mapswipe_workers/mapswipe_workers/definitions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ class CustomError(Exception):
109109

110110

111111
class MessageType(Enum):
112+
"""The different types of messages sent via Slack."""
113+
112114
SUCCESS = 1
113115
FAIL = 2
114116
NOTIFICATION_90 = 3

mapswipe_workers/python_scripts/update_project_status.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import time
3+
from typing import List
34

45
import schedule as sched
56

@@ -8,7 +9,7 @@
89
from mapswipe_workers.utils.slack_helper import send_slack_message
910

1011

11-
def get_projects(status):
12+
def get_projects(status: str) -> dict:
1213
"""Load 'active' projects from Firebase."""
1314
fb_db = firebaseDB()
1415
projects = (
@@ -18,7 +19,9 @@ def get_projects(status):
1819
return projects
1920

2021

21-
def filter_projects_by_name_and_progress(projects, filter_string, progress_threshold):
22+
def filter_projects_by_name_and_progress(
23+
projects: dict, filter_string: str, progress_threshold: int
24+
) -> List[str]:
2225
"""Filter projects by name (lowercase) and progress."""
2326
selected_project_ids = []
2427
for project_id in projects.keys():
@@ -34,7 +37,7 @@ def filter_projects_by_name_and_progress(projects, filter_string, progress_thres
3437
return selected_project_ids
3538

3639

37-
def set_status_in_firebase(project_id, project_name, new_status):
40+
def set_status_in_firebase(project_id: str, project_name: str, new_status: str) -> None:
3841
"""Change status of a project in Firebase."""
3942
# change status in firebase
4043
fb_db = firebaseDB()
@@ -50,7 +53,7 @@ def set_status_in_firebase(project_id, project_name, new_status):
5053
send_slack_message(MessageType.PROJECT_STATUS_ACTIVE, project_name, project_id)
5154

5255

53-
def run_update_project_status(filter_string):
56+
def run_update_project_status(filter_string: str) -> None:
5457
"""Run the workflow to update project status for all filtered projects."""
5558
logger.info("### Start update project status workflow ###")
5659
active_projects = get_projects(status="active")
@@ -80,6 +83,14 @@ def run_update_project_status(filter_string):
8083
if __name__ == "__main__":
8184
"""Use this command to run in docker container.
8285
docker-compose run -d mapswipe_workers_creation python3 python_scripts/update_project_status.py "test" 30 # noqa
86+
87+
You can two arguments to the script
88+
- filter string, e.g. "test"
89+
- time interval in minutes, e.g. 30
90+
91+
Make sure that you don't run this script too frequently as it pulls data from firebase and
92+
this will have implications on costs. Running this script once every 15-30 minutes should be totally fine.
93+
This means that there can be a "delay" in setting a project to finished about roughly the same time.
8394
"""
8495
try:
8596
filter_string = sys.argv[1]

0 commit comments

Comments
 (0)