1+ import sys
2+ import time
3+
4+ import schedule as sched
5+
16from mapswipe_workers .auth import firebaseDB
27from mapswipe_workers .definitions import MessageType , logger
38from mapswipe_workers .utils .slack_helper import send_slack_message
@@ -45,20 +50,22 @@ def set_status_in_firebase(project_id, project_name, new_status):
4550 send_slack_message (MessageType .PROJECT_STATUS_ACTIVE , project_name , project_id )
4651
4752
48- if __name__ == "__main__" :
49- """Check if project status should be updated and change value in Firebase."""
50- filter_string = "Test"
51-
53+ def run_update_project_status (filter_string ):
54+ """Run the workflow to update project status for all filtered projects."""
55+ logger .info ("### Start update project status workflow ###" )
5256 active_projects = get_projects (status = "active" )
5357 finished_projects = filter_projects_by_name_and_progress (
54- active_projects , filter_string , progress_threshold = 1 ,
58+ active_projects , filter_string , progress_threshold = 100 ,
5559 )
5660
5761 inactive_projects = get_projects (status = "inactive" )
5862 new_active_projects = filter_projects_by_name_and_progress (
5963 inactive_projects , filter_string , progress_threshold = 0 ,
6064 )[0 : len (finished_projects )]
6165
66+ # Here we check that there is at least one inactive project
67+ # which can be activated in the app.
68+ # We do this to avoid that there is no project left in the app.
6269 if len (new_active_projects ) > 0 :
6370 for project_id in finished_projects :
6471 project_name = active_projects [project_id ]["name" ]
@@ -67,3 +74,22 @@ def set_status_in_firebase(project_id, project_name, new_status):
6774 for project_id in new_active_projects :
6875 project_name = inactive_projects [project_id ]["name" ]
6976 set_status_in_firebase (project_id , project_name , new_status = "active" )
77+ logger .info ("### Finished update project status workflow ###" )
78+
79+
80+ if __name__ == "__main__" :
81+ """Check if project status should be updated and change value in Firebase."""
82+ try :
83+ filter_string = sys .argv [1 ]
84+ time_interval = int (sys .argv [2 ])
85+ except IndexError :
86+ logger .info ("Please provide the filter_string and time_interval arguments." )
87+ sys .exit (1 )
88+
89+ sched .every (time_interval ).minutes .do (
90+ run_update_project_status , filter_string = filter_string
91+ ).run ()
92+
93+ while True :
94+ sched .run_pending ()
95+ time .sleep (1 )
0 commit comments