mirror of
https://gitlab.com/megazordpobeda/DataRush.git
synced 2026-05-23 00:27:11 +00:00
some lol and keks
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import docker.errors
|
||||
from fastapi import FastAPI, HTTPException, status
|
||||
from pydantic import BaseModel, Field, HttpUrl, constr
|
||||
from pydantic import BaseModel, Field, HttpUrl
|
||||
import aiohttp
|
||||
import asyncio
|
||||
import docker
|
||||
@@ -20,13 +21,24 @@ ALLOWED_FILENAME_CHARS = r"[^a-zA-Z0-9_\-.]"
|
||||
|
||||
app = FastAPI()
|
||||
docker_client = docker.from_env()
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
docker_client.login(
|
||||
username=config.REGISTRY_LOGIN,
|
||||
password=config.REGISTRY_PASSWORD,
|
||||
registry=config.REGISTRY_URL,
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
async def pull_docker_image():
|
||||
client = docker.from_env()
|
||||
image_name = config.DOCKER_IMAGE
|
||||
try:
|
||||
client.images.pull(image_name)
|
||||
print(f"Successfully pulled {image_name}")
|
||||
except docker.errors.DockerException as e:
|
||||
print(f"Error pulling {image_name}: {e}")
|
||||
|
||||
|
||||
class FileDetails(BaseModel):
|
||||
@@ -93,9 +105,7 @@ async def download_file(
|
||||
session: aiohttp.ClientSession, url: str, dest_path: str
|
||||
) -> None:
|
||||
try:
|
||||
async with session.get(
|
||||
url, timeout=aiohttp.ClientTimeout(total=30)
|
||||
) as resp:
|
||||
async with session.get(url, timeout=aiohttp.ClientTimeout(total=30)) as resp:
|
||||
if resp.status != 200:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
@@ -276,9 +286,7 @@ async def execute_code(request: ExecutionRequest) -> ExecutionResponse:
|
||||
return ExecutionResponse(
|
||||
success=success,
|
||||
hash_match=(
|
||||
result_hash == request.expected_hash
|
||||
if request.expected_hash
|
||||
else None
|
||||
result_hash == request.expected_hash if request.expected_hash else None
|
||||
),
|
||||
output=output[:5000],
|
||||
result_hash=result_hash,
|
||||
|
||||
Reference in New Issue
Block a user