@@ -6145,6 +6145,13 @@ def register(runners: DbtProjectContainer) -> Union[ServerResetResult, ServerErr
61456145
61466146 runners [project ] = new_runner
61476147 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+
61486155 return asdict (ServerRegisterResult (added = project , projects = runners .registered_projects ()))
61496156
61506157
@@ -6432,4 +6439,22 @@ def run_server(runner: Optional[DbtProject] = None, host="localhost", port=8581)
64326439 )
64336440 sys .exit (1 )
64346441
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+
64356460 run_server (host = args .host , port = args .port )
0 commit comments