@@ -6145,6 +6145,13 @@ def register(runners: DbtProjectContainer) -> Union[ServerResetResult, ServerErr
6145
6145
6146
6146
runners [project ] = new_runner
6147
6147
runners .add_parsed_project
6148
+
6149
+ # If we got this far, then it means we were able to register. Save
6150
+ # our registration state.
6151
+ with open ('/tmp/savestate.json' , 'wt' ) as output :
6152
+ kwargs ['project' ] = project
6153
+ json .dump (kwargs , output )
6154
+
6148
6155
return asdict (ServerRegisterResult (added = project , projects = runners .registered_projects ()))
6149
6156
6150
6157
@@ -6432,4 +6439,22 @@ def run_server(runner: Optional[DbtProject] = None, host="localhost", port=8581)
6432
6439
)
6433
6440
sys .exit (1 )
6434
6441
6442
+ # Reload our state if necessary
6443
+ if os .path .isfile ('/tmp/savestate.json' ):
6444
+ LOGGER .info ("Found savestate file, trying to load it..." )
6445
+
6446
+ with open ('/tmp/savestate.json' , 'rt' ) as input :
6447
+ kwargs = json .load (input )
6448
+ project = kwargs ['project' ]
6449
+ del kwargs ['project' ]
6450
+
6451
+ try :
6452
+ new_runner = DbtProject (** kwargs )
6453
+ runners [project ] = new_runner
6454
+ runners .add_parsed_project
6455
+
6456
+ except Exception as init_error :
6457
+ LOGGER .error ("Failed to load savestate:" , init_error )
6458
+ LOGGER .error ("We'll continue on without trying to restore." )
6459
+
6435
6460
run_server (host = args .host , port = args .port )
0 commit comments