Commit
·
613ae81
1
Parent(s):
78c135b
make archiver non-periodic due to event blocking main loop.
Browse files- Pipfile +0 -1
- Pipfile.lock +0 -8
- main.py +1 -19
- utils/archiver.py +8 -3
Pipfile
CHANGED
@@ -12,7 +12,6 @@ requests = "*"
|
|
12 |
python-multipart = "*"
|
13 |
fastapi = "*"
|
14 |
uvicorn = "*"
|
15 |
-
apscheduler = "*"
|
16 |
|
17 |
[dev-packages]
|
18 |
|
|
|
12 |
python-multipart = "*"
|
13 |
fastapi = "*"
|
14 |
uvicorn = "*"
|
|
|
15 |
|
16 |
[dev-packages]
|
17 |
|
Pipfile.lock
CHANGED
@@ -32,14 +32,6 @@
|
|
32 |
"markers": "python_version >= '3.7'",
|
33 |
"version": "==3.7.1"
|
34 |
},
|
35 |
-
"apscheduler": {
|
36 |
-
"hashes": [
|
37 |
-
"sha256:e6df071b27d9be898e486bc7940a7be50b4af2e9da7c08f0744a96d4bd4cef4a",
|
38 |
-
"sha256:fb91e8a768632a4756a585f79ec834e0e27aad5860bac7eaa523d9ccefd87661"
|
39 |
-
],
|
40 |
-
"index": "pypi",
|
41 |
-
"version": "==3.10.4"
|
42 |
-
},
|
43 |
"av": {
|
44 |
"hashes": [
|
45 |
"sha256:04cd0ce13a87870fb0a0ea4673f04934af2b9ac7ae844eafe92e2c19c092ab11",
|
|
|
32 |
"markers": "python_version >= '3.7'",
|
33 |
"version": "==3.7.1"
|
34 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
"av": {
|
36 |
"hashes": [
|
37 |
"sha256:04cd0ce13a87870fb0a0ea4673f04934af2b9ac7ae844eafe92e2c19c092ab11",
|
main.py
CHANGED
@@ -1,17 +1,13 @@
|
|
1 |
-
from fastapi import FastAPI, UploadFile, HTTPException,
|
2 |
from fastapi.responses import FileResponse, HTMLResponse
|
3 |
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
4 |
from typing import Optional
|
5 |
from utils.process_video import process_video
|
6 |
from utils.zip_response import zip_response
|
7 |
from utils.api_configs import api_configs
|
8 |
-
from utils.archiver import archiver
|
9 |
-
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
10 |
-
from datetime import datetime
|
11 |
import shutil, os, logging, uvicorn, secrets
|
12 |
|
13 |
app = FastAPI()
|
14 |
-
scheduler = AsyncIOScheduler()
|
15 |
security = HTTPBasic()
|
16 |
api_configs_file = os.path.abspath("api_config_example.yml")
|
17 |
|
@@ -32,20 +28,6 @@ logging.basicConfig(filename='main.log',
|
|
32 |
format='%(asctime)s %(levelname)s %(message)s',
|
33 |
datefmt='%m/%d/%Y %I:%M:%S %p')
|
34 |
|
35 |
-
# # 0 6 * * 6
|
36 |
-
# @pycron.cron("*/5 * * * *")
|
37 |
-
async def periodic_archiver(timestamp: datetime):
|
38 |
-
archive = os.path.abspath(os.path.join(os.getcwd(),"archive/"))
|
39 |
-
archiver(archive, timestamp)
|
40 |
-
logging.info(f"Archive writen at {timestamp}")
|
41 |
-
|
42 |
-
@app.on_event("startup")
|
43 |
-
def start_periodic_task():
|
44 |
-
# Schedule the job to run once every day at 3:00 AM
|
45 |
-
scheduler.add_job(periodic_archiver(datetime.now()), "cron", minute="*/2")
|
46 |
-
scheduler.start()
|
47 |
-
|
48 |
-
|
49 |
@app.get("/")
|
50 |
async def root():
|
51 |
return {"message": "Hello from multilang-asr-captioner"}
|
|
|
1 |
+
from fastapi import FastAPI, UploadFile, HTTPException, File, Form, Depends
|
2 |
from fastapi.responses import FileResponse, HTMLResponse
|
3 |
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
4 |
from typing import Optional
|
5 |
from utils.process_video import process_video
|
6 |
from utils.zip_response import zip_response
|
7 |
from utils.api_configs import api_configs
|
|
|
|
|
|
|
8 |
import shutil, os, logging, uvicorn, secrets
|
9 |
|
10 |
app = FastAPI()
|
|
|
11 |
security = HTTPBasic()
|
12 |
api_configs_file = os.path.abspath("api_config_example.yml")
|
13 |
|
|
|
28 |
format='%(asctime)s %(levelname)s %(message)s',
|
29 |
datefmt='%m/%d/%Y %I:%M:%S %p')
|
30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
@app.get("/")
|
32 |
async def root():
|
33 |
return {"message": "Hello from multilang-asr-captioner"}
|
utils/archiver.py
CHANGED
@@ -1,11 +1,16 @@
|
|
1 |
import shutil, os
|
2 |
from datetime import datetime
|
3 |
|
4 |
-
def archiver(
|
|
|
5 |
TEMP_DIR = os.path.abspath("temp/")
|
6 |
LOG_FILE = os.path.abspath("main.log")
|
7 |
if os.path.exists(TEMP_DIR):
|
8 |
-
shutil.make_archive(os.path.join(
|
9 |
shutil.rmtree(TEMP_DIR)
|
10 |
if os.path.exists(LOG_FILE):
|
11 |
-
os.
|
|
|
|
|
|
|
|
|
|
1 |
import shutil, os
|
2 |
from datetime import datetime
|
3 |
|
4 |
+
def archiver(timestamp:datetime):
|
5 |
+
ARCHIVE = os.path.abspath(f"archive/{timestamp.year:4d}-{timestamp.month:2d}-{timestamp.day:2d}/")
|
6 |
TEMP_DIR = os.path.abspath("temp/")
|
7 |
LOG_FILE = os.path.abspath("main.log")
|
8 |
if os.path.exists(TEMP_DIR):
|
9 |
+
shutil.make_archive(os.path.join(ARCHIVE, "files"), 'zip', TEMP_DIR)
|
10 |
shutil.rmtree(TEMP_DIR)
|
11 |
if os.path.exists(LOG_FILE):
|
12 |
+
shutil.copy(LOG_FILE, os.path.join(ARCHIVE, f"{timestamp.year:4d}-{timestamp.month:2d}-{timestamp.day:2d}.log"))
|
13 |
+
os.remove(LOG_FILE)
|
14 |
+
|
15 |
+
if __name__ == '__main__':
|
16 |
+
archiver(timestamp=datetime.now())
|