Skip to content

Commit

Permalink
Problem: could not start Instances from command line (#597)
Browse files Browse the repository at this point in the history
Problem: could not start Instances from command line

Problem  happened when launching with --run-fake-instance
Solution: Adapt to new VMPool API that take a loop
Also fix benchmarks function
  • Loading branch information
olethanh authored and hoh committed Apr 26, 2024
1 parent b7d9202 commit 54680ba
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/aleph/vm/orchestrator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from sqlalchemy.ext.asyncio import create_async_engine

from aleph.vm.conf import ALLOW_DEVELOPER_SSH_KEYS, make_db_url, settings
from aleph.vm.models import VmExecution
from aleph.vm.pool import VmPool
from aleph.vm.version import get_version_from_apt, get_version_from_git

Expand Down Expand Up @@ -187,7 +188,8 @@ async def fake_read() -> bytes:

bench: list[float] = []

pool = VmPool()
loop = asyncio.get_event_loop()
pool = VmPool(loop)
pool.setup()

# Does not make sense in benchmarks
Expand Down Expand Up @@ -236,25 +238,24 @@ async def fake_read() -> bytes:
print("Event result", result)


async def start_instance(item_hash: ItemHash) -> None:
async def start_instance(item_hash: ItemHash, pubsub: Optional[PubSub], pool) -> VmExecution:
"""Run an instance from an InstanceMessage."""
pool = VmPool()
return await start_persistent_vm(item_hash, pubsub, pool)


async def run_instances(instances: list[ItemHash]) -> None:
"""Run instances from a list of message identifiers."""
logger.info(f"Instances to run: {instances}")
loop = asyncio.get_event_loop()
pool = VmPool(loop)
# The main program uses a singleton pubsub instance in order to watch for updates.
# We create another instance here since that singleton is not initialized yet.
# Watching for updates on this instance will therefore not work.
pubsub: Optional[PubSub] = None

await start_persistent_vm(item_hash, pubsub, pool)


async def run_instances(instances: list[ItemHash]) -> None:
"""Run instances from a list of message identifiers."""
logger.info(f"Instances to run: {instances}")
await asyncio.gather(*[start_instance(instance_id, pubsub, pool) for instance_id in instances])

await asyncio.gather(*[start_instance(item_hash=instance_id) for instance_id in instances])
await asyncio.Event().wait() # wait forever
# TODO : should we really wait forever?


@contextlib.contextmanager
Expand Down

0 comments on commit 54680ba

Please sign in to comment.