有没有一种方法可以强制执行模块间的依赖关系/初始化顺序? [英] Is there a way to enforce inter-module dependencies/initialization order?

查看:118
本文介绍了有没有一种方法可以强制执行模块间的依赖关系/初始化顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Azure IoT Edge,我没有找到任何方法来保证部署中容器/模块的初始化顺序.例如,假设我有两个模块,A和B.A是服务器,而B是依赖A的客户端.据我所知,无法保证A在B之前启动.

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.

Azure IoT Edge部署模板符合Docker Engine API,我找不到通过该API强制依赖关系的任何方法.解决方法是,我不假设每个容器的代码中都在运行哪个容器.这行得通,尽管额外代码的开销并不理想,尤其是考虑到docker-compose之类的工具会使执行初始化顺序变得微不足道.

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.

我想做这样的事情(src: https://docs.docker. com/compose/compose-file/):

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

作为一种变通方法,并按照上面的示例,在web容器中,我一直在执行以下操作,以确保postgresweb执行依赖于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.

推荐答案

否,IotEdge不支持按特定顺序初始化模块. 请注意,即使可以按特定顺序启动它们来解决依赖关系,但是如果其中一个模块崩溃,您仍然会遇到问题. EdgeHub将重新启动它,但是您将失去初始化的顺序.

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(致力于IotEdge的贡献者之一)在 github上对此问题进行了解释.

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

这篇关于有没有一种方法可以强制执行模块间的依赖关系/初始化顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆