Skip to content

Commit 4ee49ed

Browse files
committed
Restart sleeping Spaces during provisioning
When provisioning a deployment to an existing Space that is STOPPED or PAUSED, the deployer now automatically restarts it. This ensures that deployments work correctly even when reusing Spaces that have been put to sleep by HuggingFace's auto-sleep mechanism. Key changes: - Check Space runtime state when updating existing Space - Call restart_space() API if Space is STOPPED or PAUSED - Add logging to indicate when Space is being restarted This fixes the bug where deployments would fail silently when the target Space was in a sleeping state.
1 parent b1397c9 commit 4ee49ed

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/zenml/integrations/huggingface/deployers/huggingface_deployer.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,22 @@ def do_provision_deployment(
303303
)
304304

305305
try:
306+
from huggingface_hub import SpaceStage
306307
from huggingface_hub.errors import HfHubHTTPError
307308

308309
# Create Space if it doesn't exist, or update visibility if needed
309310
try:
310311
space_info = api.space_info(space_id)
311312
logger.info(f"Updating existing Space: {space_id}")
312313

314+
# Check if Space is sleeping/paused and restart it
315+
runtime = api.get_space_runtime(repo_id=space_id)
316+
if runtime.stage in [SpaceStage.STOPPED, SpaceStage.PAUSED]:
317+
logger.info(
318+
f"Space {space_id} is {runtime.stage}. Restarting..."
319+
)
320+
api.restart_space(repo_id=space_id)
321+
313322
# Update visibility if changed
314323
if space_info.private != settings.private:
315324
logger.info(

0 commit comments

Comments
 (0)