async def main(subnet_tag, payment_driver, payment_network, port):
payment_driver=payment_driver,
payment_network=payment_network,
network = await golem.create_network("192.168.0.1/24")
db_cluster = await golem.run_service(DbService, network=network)
db_instance = db_cluster.instances[0]
def still_starting(cluster):
i.state in (ServiceState.pending, ServiceState.starting)
for i in cluster.instances
def raise_exception_if_still_starting(cluster):
if still_starting(cluster):
f"Failed to start {cluster} instances "
f"after {STARTING_TIMEOUT.total_seconds()} seconds"
commissioning_time = datetime.now()
still_starting(db_cluster)
and datetime.now() < commissioning_time + STARTING_TIMEOUT
print(db_cluster.instances)
raise_exception_if_still_starting(db_cluster)
f"{TEXT_COLOR_CYAN}DB instance started, spawning the web server{TEXT_COLOR_DEFAULT}"
web_cluster = await golem.run_service(
instance_params=[{"db_address": db_instance.network_node.ip}],
# wait until all remote http instances are started
still_starting(web_cluster)
and datetime.now() < commissioning_time + STARTING_TIMEOUT
print(web_cluster.instances + db_cluster.instances)
raise_exception_if_still_starting(web_cluster)
# service instances started, start the local HTTP server
proxy = LocalHttpProxy(web_cluster, port)
f"{TEXT_COLOR_CYAN}Local HTTP server listening on:\nhttp://localhost:{port}{TEXT_COLOR_DEFAULT}"
print(web_cluster.instances + db_cluster.instances)
except (KeyboardInterrupt, asyncio.CancelledError):
# perform the shutdown of the local http server and the service cluster
print(f"{TEXT_COLOR_CYAN}HTTP server stopped{TEXT_COLOR_DEFAULT}")
s.is_available for s in web_cluster.instances + db_cluster.instances
print(web_cluster.instances + db_cluster.instances)