44import json
55import time
66
7- import click
87import schedule as sched
8+
9+ import click
910from mapswipe_workers import auth
1011from mapswipe_workers .definitions import (
1112 PROJECT_TYPE_CLASSES ,
12- PROJECT_TYPE_NAMES ,
1313 CustomError ,
1414 logger ,
15+ sentry ,
1516)
1617from mapswipe_workers .firebase_to_postgres import (
1718 archive_project ,
2021)
2122from mapswipe_workers .generate_stats import generate_stats
2223from mapswipe_workers .project_types .build_area import build_area_tutorial
23- from mapswipe_workers .project_types .change_detection import (
24- change_detection_tutorial ,
25- )
26- from mapswipe_workers .utils import sentry , slack , user_management
24+ from mapswipe_workers .project_types .change_detection import change_detection_tutorial
25+ from mapswipe_workers .utils import user_management
26+ from mapswipe_workers .utils .slack_helper import send_slack_message
2727
2828
2929class PythonLiteralOption (click .Option ):
@@ -63,6 +63,7 @@ def run_create_projects():
6363 for project_draft_id , project_draft in project_drafts .items ():
6464 project_draft ["projectDraftId" ] = project_draft_id
6565 project_type = project_draft ["projectType" ]
66+ project_name = project_draft ["name" ]
6667 try :
6768 # Create a project object using appropriate class (project type).
6869 project = PROJECT_TYPE_CLASSES [project_type ](project_draft )
@@ -71,37 +72,15 @@ def run_create_projects():
7172 project .calc_required_results ()
7273 # Save project and its groups and tasks to Firebase and Postgres.
7374 project .save_project ()
74- newline = "\n "
75- message = (
76- f"### PROJECT CREATION SUCCESSFUL ###{ newline } "
77- f"Project Name: { project .name } { newline } "
78- f"Project Id: { project .projectId } { newline } "
79- f"Project Type: { PROJECT_TYPE_NAMES [project_type ]} "
80- f"{ newline } "
81- f"Make sure to activate the project "
82- f"using the manager dashboard."
83- f"{ newline } "
84- f"Happy Swiping. :)"
85- )
86- slack .send_slack_message (message )
87- logger .info (message )
8875 except CustomError :
8976 ref = fb_db .reference (f"v2/projectDrafts/{ project_draft_id } " )
9077 ref .set ({})
91- newline = "\n "
92- message = (
93- f"### PROJECT CREATION FAILED ###{ newline } "
94- f'Project Name: { project_draft ["name" ]} { newline } '
95- f"Project Id: { project_draft_id } { newline } "
96- f"{ newline } "
97- f"Project draft is deleted.{ newline } "
98- f"Please check what went wrong."
99- )
100- slack .send_slack_message (message )
101- slack .send_error (CustomError )
102- logger .exception (f"{ project_draft_id } " f"- project creation failed" )
78+ send_slack_message ("fail" , project_name , project .projectId )
79+ logger .exception ("Failed: Project Creation ({0}))" .format (project_name ))
10380 sentry .capture_exception ()
104- continue
81+ send_slack_message ("success" , project_name , project .projectId )
82+ logger .info ("Success: Project Creation ({0})" .format (project_name ))
83+ continue
10584
10685
10786@cli .command ("firebase-to-postgres" )
@@ -154,10 +133,9 @@ def run_user_management(email, manager) -> None:
154133 user_management .set_project_manager_rights (email )
155134 elif not manager :
156135 user_management .remove_project_manager_rights (email )
157- except Exception as e :
158- slack .send_error (e )
159- sentry .capture_exception_sentry (e )
160- logger .exception (e )
136+ except Exception :
137+ logger .exception ()
138+ sentry .capture_exception ()
161139
162140
163141@cli .command ("create-tutorial" )
@@ -181,20 +159,15 @@ def run_create_tutorial(input_file) -> None:
181159 1 : build_area_tutorial .create_tutorial ,
182160 3 : change_detection_tutorial .create_tutorial ,
183161 }
184-
185162 project_types_tutorial [project_type ](tutorial )
186- except Exception as e :
187- slack .send_error (e )
188- sentry .capture_exception_sentry (e )
189- logger .exception (e )
163+ except Exception :
164+ logger .exception ()
165+ sentry .capture_exception ()
190166
191167
192168@click .command ("archive" )
193169@click .option (
194- "--project-id" ,
195- "-i" ,
196- help = ("Archive project with giving project id" ),
197- type = str ,
170+ "--project-id" , "-i" , help = ("Archive project with giving project id" ), type = str ,
198171)
199172@click .option (
200173 "--project-ids" ,
@@ -237,4 +210,4 @@ def _run():
237210 sched .run_pending ()
238211 time .sleep (1 )
239212 else :
240- _run ()
213+ _run ()
0 commit comments