plaggy commited on
Commit
ce236eb
·
1 Parent(s): 770c645

sha stored in a set

Browse files
Files changed (1) hide show
  1. src/main.py +4 -4
src/main.py CHANGED
@@ -38,7 +38,7 @@ INPUT_TEXT_COL = os.getenv("INPUT_TEXT_COL")
38
  INPUT_SPLITS = [spl.strip() for spl in INPUT_SPLITS.split(",") if spl]
39
 
40
  app = FastAPI()
41
- app.state.last_Sha = None
42
 
43
 
44
  @app.get("/")
@@ -56,13 +56,13 @@ async def post_webhook(
56
  and payload.event.scope.startswith("repo.content")
57
  and payload.repo.type == "dataset"
58
  # webhook posts multiple requests with the same update, this addresses that
59
- and (not app.state.last_Sha or app.state.last_Sha != payload.repo.headSha)
60
  ):
61
  # no-op
62
  logger.info("Update detected, no action taken")
63
  return {"processed": False}
64
 
65
- app.state.last_Sha = payload.repo.headSha
66
  task_queue.add_task(chunk_dataset, ds_name=payload.repo.name)
67
  task_queue.add_task(embed_dataset, ds_name=CHUNKED_DS_NAME)
68
 
@@ -181,7 +181,7 @@ def wake_up_endpoint(url):
181
  ).status_code != 200:
182
  time.sleep(2)
183
  n_loop += 1
184
- if n_loop > 30:
185
  raise TimeoutError("TEI endpoint is unavailable")
186
  logger.info("TEI endpoint is up")
187
 
 
38
  INPUT_SPLITS = [spl.strip() for spl in INPUT_SPLITS.split(",") if spl]
39
 
40
  app = FastAPI()
41
+ app.state.seen_Sha = set()
42
 
43
 
44
  @app.get("/")
 
56
  and payload.event.scope.startswith("repo.content")
57
  and payload.repo.type == "dataset"
58
  # webhook posts multiple requests with the same update, this addresses that
59
+ and payload.repo.headSha not in app.state.last_Sha
60
  ):
61
  # no-op
62
  logger.info("Update detected, no action taken")
63
  return {"processed": False}
64
 
65
+ app.state.last_Sha.add(payload.repo.headSha)
66
  task_queue.add_task(chunk_dataset, ds_name=payload.repo.name)
67
  task_queue.add_task(embed_dataset, ds_name=CHUNKED_DS_NAME)
68
 
 
181
  ).status_code != 200:
182
  time.sleep(2)
183
  n_loop += 1
184
+ if n_loop > 40:
185
  raise TimeoutError("TEI endpoint is unavailable")
186
  logger.info("TEI endpoint is up")
187