Is there a way to enforce inter-module dependencies/initialization order?

梦想的初衷 提交于 2020-05-24 04:59:10

问题


Using Azure IoT Edge, I have not found any way to guarantee the initialization order of containers/modules in a deployment. Suppose for example, I have 2 modules, A and B. A is a server and B is a client that depends on A. As far as I know, there's no way to guarantee that A starts up before B does.

The Azure IoT Edge deployment templates conform to the Docker Engine API, and I could not find any way to enforce dependencies through that API. As a workaround, I make no assumptions about which containers are running in each container's code. This works, although the overhead of additional code is not ideal, especially considering a tool like docker-compose would make enforcing initialization order rather trivial.

I want to do something like this (src: https://docs.docker.com/compose/compose-file/):

version: "3.7"
services:
  web:
    build: .
    depends_on:
      - db
      - redis
  redis:
    image: redis
  db:
    image: postgres

As a workaround, and following the example above, in the web container I've been doing things like the following to ensure postgres is up and running before web performs postgres dependent actions:

postgresIsUp = False
while not postgresIsUp:
    try:
        pingPostgres()
        postgresIsUp = True
    except PingError:
        print("postgres is not yet running")

This is, of course, a contrived example with obvious flaws, but it demonstrates the gist of the workaround.


回答1:


No, IotEdge does not support the initialization of modules in a specific order. Please be aware that even if it would be possible to start them in a specific order to resolve dependencies, you would still be running into problems if one of the modules crashes. It will be restarted by EdgeHub but you would loose the order of initialization.

Mike Yagley (one of the contributors working on IotEdge) gives an explanation on this issue on github.



来源:https://stackoverflow.com/questions/56046148/is-there-a-way-to-enforce-inter-module-dependencies-initialization-order

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!