Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -144,7 +144,7 @@ async def status_check():
|
|
| 144 |
return {"Status": "API is online..."}
|
| 145 |
|
| 146 |
|
| 147 |
-
async def endpoint_output(endpoint_result:
|
| 148 |
msg = 'Execution failed'
|
| 149 |
output = ErrorResponse(**{'execution_msg': msg,
|
| 150 |
'execution_code': code, 'error': error})
|
|
@@ -173,7 +173,7 @@ async def endpoint_output(endpoint_result: ResultItem, code: int = 0, error: str
|
|
| 173 |
# Caching Post requests is challenging
|
| 174 |
async def sms_posts(instance: Result, idx: str = None, action: str = "add") -> Union[ErrorResponse, EndpointResponse]:
|
| 175 |
async with AsyncSession(sms_resource["engine"]) as session:
|
| 176 |
-
code =
|
| 177 |
error = None
|
| 178 |
existing = await session.get(instance.__class__, idx)
|
| 179 |
|
|
@@ -184,14 +184,13 @@ async def sms_posts(instance: Result, idx: str = None, action: str = "add") -> U
|
|
| 184 |
if checker:
|
| 185 |
if action == "delete":
|
| 186 |
await session.delete(instance)
|
| 187 |
-
code = 1
|
| 188 |
await session.commit()
|
| 189 |
else: # add or update use add
|
| 190 |
session.add(instance) # Not asynchronous
|
| 191 |
-
code = 1
|
| 192 |
await session.commit()
|
| 193 |
await session.refresh(instance)
|
| 194 |
except Exception as e:
|
|
|
|
| 195 |
error = e
|
| 196 |
|
| 197 |
finally:
|
|
|
|
| 144 |
return {"Status": "API is online..."}
|
| 145 |
|
| 146 |
|
| 147 |
+
async def endpoint_output(endpoint_result: Result, code: int = 0, error: str = None) -> Union[ErrorResponse, EndpointResponse]:
|
| 148 |
msg = 'Execution failed'
|
| 149 |
output = ErrorResponse(**{'execution_msg': msg,
|
| 150 |
'execution_code': code, 'error': error})
|
|
|
|
| 173 |
# Caching Post requests is challenging
|
| 174 |
async def sms_posts(instance: Result, idx: str = None, action: str = "add") -> Union[ErrorResponse, EndpointResponse]:
|
| 175 |
async with AsyncSession(sms_resource["engine"]) as session:
|
| 176 |
+
code = 1
|
| 177 |
error = None
|
| 178 |
existing = await session.get(instance.__class__, idx)
|
| 179 |
|
|
|
|
| 184 |
if checker:
|
| 185 |
if action == "delete":
|
| 186 |
await session.delete(instance)
|
|
|
|
| 187 |
await session.commit()
|
| 188 |
else: # add or update use add
|
| 189 |
session.add(instance) # Not asynchronous
|
|
|
|
| 190 |
await session.commit()
|
| 191 |
await session.refresh(instance)
|
| 192 |
except Exception as e:
|
| 193 |
+
code = 0
|
| 194 |
error = e
|
| 195 |
|
| 196 |
finally:
|