@@ -83,10 +83,34 @@ def do_ping(*args, **job_info):
8383 send_results_to_grafolean (job_info ['backend_url' ], job_info ['bot_token' ], job_info ['account_id' ], values )
8484
8585
86+ def wait_for_grafolean (backend_url ):
87+ while True :
88+ url = '{}/status/info' .format (backend_url )
89+ log .info ("Checking Grafolean status..." )
90+ try :
91+ r = requests .get (url )
92+ r .raise_for_status ()
93+ status_info = r .json ()
94+ if status_info ['db_migration_needed' ] == False and status_info ['user_exists' ] == True :
95+ log .info ("Grafolean backend is ready." )
96+ return
97+ except :
98+ pass
99+ log .info ("Grafolean backend not available / initialized yet, waiting." )
100+ time .sleep (10 )
101+
102+
86103if __name__ == "__main__" :
87104 dotenv .load_dotenv ()
88105
89106 backend_url = os .environ .get ('BACKEND_URL' )
107+ jobs_refresh_interval = int (os .environ .get ('JOBS_REFRESH_INTERVAL' , 120 ))
108+
109+ if not backend_url :
110+ raise Exception ("Please specify BACKEND_URL and BOT_TOKEN / BOT_TOKEN_FROM_FILE env vars." )
111+
112+ wait_for_grafolean (backend_url )
113+
90114 bot_token = os .environ .get ('BOT_TOKEN' )
91115 if not bot_token :
92116 # bot token can also be specified via contents of a file:
@@ -95,9 +119,8 @@ def do_ping(*args, **job_info):
95119 with open (bot_token_from_file , 'rt' ) as f :
96120 bot_token = f .read ()
97121
98- if not backend_url or not bot_token :
99- raise Exception ("Please specify BACKEND_URL and BOT_TOKEN / BOT_TOKEN_FROM_FILE env vars." )
100- jobs_refresh_interval = int (os .environ .get ('JOBS_REFRESH_INTERVAL' , 120 ))
122+ if not bot_token :
123+ raise Exception ("Please specify BOT_TOKEN / BOT_TOKEN_FROM_FILE env var." )
101124
102125 c = PingCollector (backend_url , bot_token , jobs_refresh_interval )
103126 c .execute ()
0 commit comments