Elixir 重启频率:简单一个工人一个工人
动态创建WOKER时,如何设置重启频率?在当前设置中,辅助进程无限期地重新启动Elixir 重启频率:简单一个工人一个工人,elixir,otp,Elixir,Otp,动态创建WOKER时,如何设置重启频率?在当前设置中,辅助进程无限期地重新启动 def start_child(input) do Supervisor.start_child(@name, [input]) end def init(:ok) do children = [ worker(Kombiner.Foo, [], restart: :transient) ] supervise(children, strategy: :simple_one_for_one
def start_child(input) do
Supervisor.start_child(@name, [input])
end
def init(:ok) do
children = [
worker(Kombiner.Foo, [], restart: :transient)
]
supervise(children, strategy: :simple_one_for_one)
end
我还尝试在worker规范中设置:max_restarts(worker(Kombiner.Foo,[],max_restarts:3,max_seconds:5))
而且它似乎什么也不做(它将无限期地重新启动)
在Kombiner.Foo worker内:
def handle_info({any, :timeout}, _state) do
{:stop, :timeout, nil}
end
max_restarts:3,max_seconds:5
需要添加到supervise/2
调用的init/1
末尾,而不是子项列表中调用的worker/3
函数。您的代码应该如下所示:
def init(:ok) do
children = [
worker(Kombiner.Foo, [], restart: :transient)
]
supervise(children, strategy: :simple_one_for_one, max_restarts: 3, max_seconds: 5)
end
重新启动策略max restarts和max seconds适用于列表中的所有子项
有关更多信息,请参阅。实际上,我曾尝试将max_restart和max_seconds添加到supervise/2功能中,但主要问题是我在大约10秒内重新启动了3次,因此频率不匹配-下次我应该尝试更好地理解文档-谢谢!