Spaces:
Sleeping
Sleeping
better logic for rebuilding a space
Browse files
src/gradio_space_ci/webhook.py
CHANGED
@@ -207,7 +207,7 @@ def recover_after_restart(space_id: str) -> None:
|
|
207 |
if not is_pr_synced(space_id=space_id, pr_num=discussion.num):
|
208 |
# Found a PR that is not yet synced
|
209 |
print(f"Recovery. Found an open PR that is not synced: {discussion.url}. Syncing it.")
|
210 |
-
background_pool.submit(sync_ci_space, space_id=space_id, pr_num=discussion.num)
|
211 |
if discussion.status == "merged" or discussion.status == "closed":
|
212 |
ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=discussion.num)
|
213 |
if repo_exists(repo_id=ci_space_id, repo_type="space"):
|
@@ -264,7 +264,7 @@ async def trigger_ci_on_pr(payload: WebhookPayload, task_queue: BackgroundTasks)
|
|
264 |
# Always sync (in case the space was sleeping or building)
|
265 |
if not is_pr_synced(space_id=space_id, pr_num=payload.discussion.num):
|
266 |
# New PR! Sync task scheduled
|
267 |
-
task_queue.add_task(sync_ci_space, space_id=space_id, pr_num=payload.discussion.num)
|
268 |
has_task = True
|
269 |
elif (
|
270 |
# Means "a PR has been merged or closed"
|
@@ -286,7 +286,7 @@ async def trigger_ci_on_pr(payload: WebhookPayload, task_queue: BackgroundTasks)
|
|
286 |
if discussion.is_pull_request and discussion.status in ACTIVE_PR_STATUS:
|
287 |
if not is_pr_synced(space_id=space_id, pr_num=discussion.num):
|
288 |
# Found a PR that is not yet synced
|
289 |
-
task_queue.add_task(sync_ci_space, space_id=space_id, pr_num=discussion.num)
|
290 |
has_task = True
|
291 |
|
292 |
if has_task:
|
@@ -317,9 +317,9 @@ def is_pr_synced(space_id: str, pr_num: int) -> bool:
|
|
317 |
return last_synced_sha == last_pr_sha
|
318 |
|
319 |
|
320 |
-
def sync_ci_space(space_id: str, pr_num: int) -> None:
|
321 |
print(f"New task: sync ephemeral env for {space_id} (PR {pr_num})")
|
322 |
-
if is_pr_synced(space_id=space_id, pr_num=pr_num):
|
323 |
print("Already synced. Nothing to do.")
|
324 |
return
|
325 |
|
@@ -330,7 +330,7 @@ def sync_ci_space(space_id: str, pr_num: int) -> None:
|
|
330 |
|
331 |
# Configure ephemeral Space if trusted author
|
332 |
is_configured = False
|
333 |
-
if is_new:
|
334 |
is_configured = configure_ephemeral_space(space_id=space_id, pr_num=pr_num)
|
335 |
|
336 |
# Download space codebase from PR revision
|
@@ -477,7 +477,7 @@ def rebuild_space(space_id: str, pr_num: int) -> None:
|
|
477 |
# the ephemeral space
|
478 |
delete_ci_space(space_id=space_id, pr_num=pr_num, notify=False)
|
479 |
# create a new synced ephemeral space
|
480 |
-
sync_ci_space(space_id=space_id, pr_num=pr_num)
|
481 |
|
482 |
|
483 |
def handle_modification(space_id: str, discussion: Any) -> None:
|
|
|
207 |
if not is_pr_synced(space_id=space_id, pr_num=discussion.num):
|
208 |
# Found a PR that is not yet synced
|
209 |
print(f"Recovery. Found an open PR that is not synced: {discussion.url}. Syncing it.")
|
210 |
+
background_pool.submit(sync_ci_space, space_id=space_id, pr_num=discussion.num, skip_config=False)
|
211 |
if discussion.status == "merged" or discussion.status == "closed":
|
212 |
ci_space_id = _get_ci_space_id(space_id=space_id, pr_num=discussion.num)
|
213 |
if repo_exists(repo_id=ci_space_id, repo_type="space"):
|
|
|
264 |
# Always sync (in case the space was sleeping or building)
|
265 |
if not is_pr_synced(space_id=space_id, pr_num=payload.discussion.num):
|
266 |
# New PR! Sync task scheduled
|
267 |
+
task_queue.add_task(sync_ci_space, space_id=space_id, pr_num=payload.discussion.num, skip_config=False)
|
268 |
has_task = True
|
269 |
elif (
|
270 |
# Means "a PR has been merged or closed"
|
|
|
286 |
if discussion.is_pull_request and discussion.status in ACTIVE_PR_STATUS:
|
287 |
if not is_pr_synced(space_id=space_id, pr_num=discussion.num):
|
288 |
# Found a PR that is not yet synced
|
289 |
+
task_queue.add_task(sync_ci_space, space_id=space_id, pr_num=discussion.num, skip_config=False)
|
290 |
has_task = True
|
291 |
|
292 |
if has_task:
|
|
|
317 |
return last_synced_sha == last_pr_sha
|
318 |
|
319 |
|
320 |
+
def sync_ci_space(space_id: str, pr_num: int, skip_config: bool = False) -> None:
|
321 |
print(f"New task: sync ephemeral env for {space_id} (PR {pr_num})")
|
322 |
+
if is_pr_synced(space_id=space_id, pr_num=pr_num) and not skip_config:
|
323 |
print("Already synced. Nothing to do.")
|
324 |
return
|
325 |
|
|
|
330 |
|
331 |
# Configure ephemeral Space if trusted author
|
332 |
is_configured = False
|
333 |
+
if not skip_config and is_new:
|
334 |
is_configured = configure_ephemeral_space(space_id=space_id, pr_num=pr_num)
|
335 |
|
336 |
# Download space codebase from PR revision
|
|
|
477 |
# the ephemeral space
|
478 |
delete_ci_space(space_id=space_id, pr_num=pr_num, notify=False)
|
479 |
# create a new synced ephemeral space
|
480 |
+
sync_ci_space(space_id=space_id, pr_num=pr_num, skip_config=True)
|
481 |
|
482 |
|
483 |
def handle_modification(space_id: str, discussion: Any) -> None:
|