Skip to content

Commit

Permalink
Fix: Allow abort the process if it fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
nesitor committed Jul 31, 2023
1 parent ebe7b2e commit dca8734
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions vm_supervisor/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,28 +232,21 @@ async def run_code_on_event(vm_hash: ItemHash, event, pubsub: PubSub):
await execution.stop()


async def start_persistent_vm(
vm_hash: ItemHash, pubsub: PubSub
) -> Optional[VmExecution]:
async def start_persistent_vm(vm_hash: ItemHash, pubsub: PubSub) -> VmExecution:
execution: Optional[VmExecution] = await pool.get_running_vm(vm_hash=vm_hash)

try:
if not execution:
logger.info(f"Starting persistent virtual machine with id: {vm_hash}")
execution = await create_vm_execution(vm_hash=vm_hash)
if not execution:
logger.info(f"Starting persistent virtual machine with id: {vm_hash}")
execution = await create_vm_execution(vm_hash=vm_hash)
# If the VM was already running in lambda mode, it should not expire
# as long as it is also scheduled as long-running
execution.persistent = True
execution.cancel_expiration()
execution.persistent = True
execution.cancel_expiration()

await execution.becomes_ready()
await execution.becomes_ready()

if settings.WATCH_FOR_UPDATES:
execution.start_watching_for_updates(pubsub=pubsub)

# TODO: Handle all the exceptions, for now Always return a 200 code for now
except:
pass
if settings.WATCH_FOR_UPDATES:
execution.start_watching_for_updates(pubsub=pubsub)

return execution

Expand All @@ -262,11 +255,7 @@ async def stop_persistent_vm(vm_hash: ItemHash) -> Optional[VmExecution]:
logger.info(f"Stopping persistent VM {vm_hash}")
execution = await pool.get_running_vm(vm_hash)

try:
if execution:
await execution.stop()
# TODO: Handle all the exceptions, for now Always return a 200 code for now
except:
pass
if execution:
await execution.stop()

return execution

0 comments on commit dca8734

Please sign in to comment.