Skip to content

Commit 7139ed6

Browse files
committed
Add SKIP_PROCESSING variable to api
1 parent b81b9c5 commit 7139ed6

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

api.http

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
@file = 4178.pdf
2+
// @file = 10000.pdf
3+
14
### Start File Processing
25
POST http://localhost:8000
36
Content-Type: application/json
47

58
{
6-
"file": "4178.pdf"
9+
"file": "{{file}}"
710
}
811

912
### Collect File Result
1013
POST http://localhost:8000/collect
1114
Content-Type: application/json
1215

1316
{
14-
"file": "4178.pdf"
17+
"file": "{{file}}"
1518
}

api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import logging
12
import os
23
import shutil
34
import uuid
5+
from random import randint
6+
from time import sleep
47
from typing import Annotated
58

69
from fastapi import FastAPI, Depends, status, HTTPException, BackgroundTasks, Response
@@ -19,6 +22,9 @@ class StartPayload(BaseModel):
1922
file: str = Field(min_length=1)
2023

2124

25+
if api_settings().skip_processing:
26+
logging.warning("SKIP_PROCESSING is active, files will always be marked as completed without being proceed")
27+
2228
@app.post("/")
2329
def start(
2430
payload: StartPayload,
@@ -73,6 +79,11 @@ def process(
7379
payload: StartPayload,
7480
settings: Annotated[ApiSettings, Depends(api_settings)],
7581
):
82+
if settings.skip_processing:
83+
# Sleep between 30 seconds to 2 minutes to simulate processing time.
84+
sleep(randint(30, 120))
85+
return
86+
7687
task_id = f"{uuid.uuid4()}"
7788
tmp_dir = os.path.join(settings.tmp_path, task_id)
7889
os.makedirs(tmp_dir, exist_ok=True)

utils/settings.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ class SharedSettings(BaseSettings):
1515

1616
class ApiSettings(SharedSettings):
1717
aws_profile: str | None = None
18-
aws_access_key: str | None = None
19-
aws_secret_access_key: str | None = None
20-
aws_region: str | None = None
18+
skip_processing: bool = False
2119

2220
s3_input_bucket: str
2321
s3_input_folder: str

0 commit comments

Comments
 (0)