     end
   end
 
+  def handle_info({:DOWN, _, :process, pid, reason}, %{conn: %{pid: pid}} = state) do
+    {:stop, reason, state}
+  end
+
+  def handle_info({:DOWN, _, :process, pid, reason}, %{chan: %{pid: pid}} = state) do
+    {:stop, reason, state}
+  end
+
   def handle_info({:DOWN, _, :process, pid, reason}, state) do
     unless reason in [:normal, :noproc] do
       Logger.warn 3, "CeleryScript: #{inspect pid} died: #{inspect reason}"


  def init([]) do
    token = ConfigStorage.get_config_value(:string, "authorization", "token")

    import Farmbot.Jwt, only: [decode: 1]
    with {:ok, %{bot: device, mqtt: mqtt_host, vhost: vhost}} <- decode(token),
         {:ok, conn}  <- open_connection(token, device, mqtt_host, vhost),
         {:ok, chan}  <- AMQP.Channel.open(conn),
         q_base       <- device,



         {:ok, _tag}  <- Basic.consume(chan, q_base <> "_from_clients", self(), [no_ack: true]),
         {:ok, _tag}  <- Basic.consume(chan, q_base <> "_auto_sync", self(), [no_ack: true]),
         state <- %State{conn: conn, chan: chan, bot: device}
    do
      _ = Process.monitor(conn.pid)
      _ = Process.monitor(chan.pid)
      _ = Process.flag(:sensitive, true)
      _ = Process.flag(:trap_exit, true)
      {:consumer, state, subscribe_to: [Farmbot.BotState, Farmbot.Logger]}
    else
      {:error, {:auth_failure, msg}} = fail ->
