@@ -56,7 +56,7 @@ def create_simulation(
5656 policy_id : int ,
5757 ) -> dict :
5858 """
59- Create a new simulation record.
59+ Create a new simulation record with pending status .
6060
6161 Args:
6262 country_id (str): The country ID.
@@ -72,13 +72,14 @@ def create_simulation(
7272
7373 try :
7474 database .query (
75- "INSERT INTO simulations (country_id, api_version, population_id, population_type, policy_id) VALUES (?, ?, ?, ?, ?)" ,
75+ "INSERT INTO simulations (country_id, api_version, population_id, population_type, policy_id, status ) VALUES (?, ?, ?, ?, ?, ?)" ,
7676 (
7777 country_id ,
7878 api_version ,
7979 population_id ,
8080 population_type ,
8181 policy_id ,
82+ "pending" ,
8283 ),
8384 )
8485
@@ -135,24 +136,28 @@ def get_simulation(
135136 )
136137 raise e
137138
138- def update_simulation_output (
139+ def update_simulation (
139140 self ,
140141 country_id : str ,
141142 simulation_id : int ,
142- output_json : str | None = None ,
143+ status : str | None = None ,
144+ output : str | None = None ,
145+ error_message : str | None = None ,
143146 ) -> bool :
144147 """
145- Update a simulation record with calculation output .
148+ Update a simulation record with results or error .
146149
147150 Args:
148151 country_id (str): The country ID.
149152 simulation_id (int): The simulation ID.
150- output_json (str | None): The output as JSON string (for household simulations).
153+ status (str | None): The new status ('complete' or 'error').
154+ output (str | None): The result output as JSON string (for complete status).
155+ error_message (str | None): The error message (for error status).
151156
152157 Returns:
153158 bool: True if update was successful.
154159 """
155- print (f"Updating simulation { simulation_id } with output " )
160+ print (f"Updating simulation { simulation_id } " )
156161 # Automatically update api_version on every update to latest
157162 api_version : str = COUNTRY_PACKAGE_VERSIONS .get (country_id )
158163
@@ -161,10 +166,18 @@ def update_simulation_output(
161166 update_fields = []
162167 update_values = []
163168
164- if output_json is not None :
165- update_fields .append ("output_json = ?" )
169+ if status is not None :
170+ update_fields .append ("status = ?" )
171+ update_values .append (status )
172+
173+ if output is not None :
174+ update_fields .append ("output = ?" )
166175 # Output is already a JSON string from frontend
167- update_values .append (output_json )
176+ update_values .append (output )
177+
178+ if error_message is not None :
179+ update_fields .append ("error_message = ?" )
180+ update_values .append (error_message )
168181
169182 # Always update API version
170183 update_fields .append ("api_version = ?" )
0 commit comments