Spaces:
Runtime error
Runtime error
not schedule duplicated calls
Browse files- src/main.py +9 -7
src/main.py
CHANGED
@@ -25,6 +25,7 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
25 |
TEI_URL = os.getenv("TEI_URL")
|
26 |
|
27 |
app = FastAPI()
|
|
|
28 |
|
29 |
|
30 |
@app.get("/")
|
@@ -40,16 +41,17 @@ async def post_webhook(
|
|
40 |
if not (
|
41 |
payload.event.action == "update"
|
42 |
and payload.event.scope.startswith("repo.content")
|
43 |
-
|
44 |
and payload.repo.type == "dataset"
|
|
|
45 |
):
|
46 |
# no-op
|
47 |
logger.info("Update detected, no action taken")
|
48 |
return {"processed": False}
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
|
54 |
return {"processed": True}
|
55 |
|
@@ -187,6 +189,6 @@ def embed_dataset():
|
|
187 |
|
188 |
# For debugging
|
189 |
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
25 |
TEI_URL = os.getenv("TEI_URL")
|
26 |
|
27 |
app = FastAPI()
|
28 |
+
app.state.last_Sha = None
|
29 |
|
30 |
|
31 |
@app.get("/")
|
|
|
41 |
if not (
|
42 |
payload.event.action == "update"
|
43 |
and payload.event.scope.startswith("repo.content")
|
44 |
+
and payload.repo.name == chunk_config.input_dataset
|
45 |
and payload.repo.type == "dataset"
|
46 |
+
and (not app.state.last_Sha or app.state.last_Sha != payload.repo.headSha)
|
47 |
):
|
48 |
# no-op
|
49 |
logger.info("Update detected, no action taken")
|
50 |
return {"processed": False}
|
51 |
|
52 |
+
app.state.last_Sha = payload.repo.headSha
|
53 |
+
task_queue.add_task(chunk_dataset)
|
54 |
+
task_queue.add_task(embed_dataset)
|
55 |
|
56 |
return {"processed": True}
|
57 |
|
|
|
189 |
|
190 |
# For debugging
|
191 |
|
192 |
+
import uvicorn
|
193 |
+
if __name__ == "__main__":
|
194 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|