Fix more namespaces
parent
95bd827518
commit
218b33785d
|
@ -1,5 +1,9 @@
|
|||
use Mix.Config
|
||||
|
||||
config :logger,
|
||||
handle_otp_reports: true,
|
||||
handle_sasl_reports: true
|
||||
handle_otp_reports: false,
|
||||
handle_sasl_reports: false
|
||||
|
||||
config :lagger,
|
||||
handlers: [],
|
||||
extra_sinks: []
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
defmodule FarmbotCore do
|
||||
@moduledoc """
|
||||
Core Farmbot Services.
|
||||
This includes Logging, Configuration, Asset management and Firmware.
|
||||
This includes
|
||||
* Core global state management
|
||||
* Data storage management
|
||||
* Firmware management
|
||||
* RPC and IPC management
|
||||
|
||||
"""
|
||||
use Application
|
||||
|
||||
|
@ -12,15 +17,10 @@ defmodule FarmbotCore do
|
|||
|
||||
children = [
|
||||
FarmbotCore.EctoMigrator,
|
||||
# TODO(Connor) - Put these in their own supervisor
|
||||
FarmbotCore.BotState,
|
||||
FarmbotCore.BotState.FileSystem,
|
||||
FarmbotCore.Logger.Supervisor,
|
||||
FarmbotCore.Config.Supervisor,
|
||||
FarmbotCore.Asset.Supervisor,
|
||||
FarmbotCore.FirmwareSupervisor,
|
||||
FarmbotCeleryScript.Scheduler,
|
||||
FarmbotCore.BotState.Supervisor,
|
||||
FarmbotCore.StorageSupervisor,
|
||||
FarmbotCeleryScript.Scheduler
|
||||
]
|
||||
Supervisor.init(children, [strategy: :one_for_all])
|
||||
Supervisor.init(children, [strategy: :one_for_one])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,6 +21,7 @@ defimpl FarmbotCore.AssetWorker, for: FarmbotCore.Asset.FbosConfig do
|
|||
end
|
||||
|
||||
def handle_info(:timeout, %FbosConfig{} = fbos_config) do
|
||||
Logger.warn "Setting config to state"
|
||||
:ok = BotState.set_config_value(:arduino_debug_messages, fbos_config.arduino_debug_messages)
|
||||
:ok = BotState.set_config_value(:auto_sync, fbos_config.auto_sync)
|
||||
:ok = BotState.set_config_value(:beta_opt_in, fbos_config.beta_opt_in)
|
||||
|
@ -40,6 +41,7 @@ defimpl FarmbotCore.AssetWorker, for: FarmbotCore.Asset.FbosConfig do
|
|||
current_hardware = get_config_value(:string, "settings", "firmware_hardware")
|
||||
|
||||
if current_hardware != target_hardware do
|
||||
raise("firmware hardware change")
|
||||
Logger.debug("Updating firmware_hardware from #{current_hardware} to #{target_hardware}")
|
||||
update_config_value(:string, "settings", "firmware_hardware", target_hardware)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
defmodule FarmbotCore.BotState.Supervisor do
|
||||
use Supervisor
|
||||
|
||||
def start_link(args) do
|
||||
Supervisor.start_link(__MODULE__, args, [name: __MODULE__])
|
||||
end
|
||||
|
||||
def init([]) do
|
||||
children = [
|
||||
FarmbotCore.BotState,
|
||||
FarmbotCore.BotState.FileSystem
|
||||
]
|
||||
Supervisor.init(children, [strategy: :one_for_one])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
defmodule FarmbotCore.StorageSupervisor do
|
||||
use Supervisor
|
||||
|
||||
def start_link(args) do
|
||||
Supervisor.start_link(__MODULE__, args, [name: __MODULE__])
|
||||
end
|
||||
|
||||
def init([]) do
|
||||
children = [
|
||||
FarmbotCore.Logger.Supervisor,
|
||||
FarmbotCore.Config.Supervisor,
|
||||
FarmbotCore.Asset.Supervisor
|
||||
]
|
||||
Supervisor.init(children, [strategy: :one_for_one])
|
||||
end
|
||||
end
|
|
@ -65,7 +65,6 @@ defmodule FarmbotCore.MixProject do
|
|||
defp deps do
|
||||
[
|
||||
{:farmbot_celery_script, path: "../farmbot_celery_script", env: Mix.env()},
|
||||
{:farmbot_firmware, path: "../farmbot_firmware", env: Mix.env()},
|
||||
{:elixir_make, "~> 0.4", runtime: false},
|
||||
{:sqlite_ecto2, "~> 2.3"},
|
||||
{:timex, "~> 3.4"},
|
||||
|
|
|
@ -30,5 +30,8 @@ config :farmbot_core, FarmbotCore.Core.CeleryScript.RunTimeWrapper,
|
|||
config :farmbot_core, FarmbotCore.EctoMigrator,
|
||||
default_firmware_io_logs: false,
|
||||
default_server: "https://my.farm.bot",
|
||||
default_dns_name: "my.farm.bot",
|
||||
default_ntp_server_1: "0.pool.ntp.org",
|
||||
default_ntp_server_2: "1.pool.ntp.org",
|
||||
default_currently_on_beta:
|
||||
String.contains?(to_string(:os.cmd('git rev-parse --abbrev-ref HEAD')), "beta")
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
use Mix.Config
|
||||
|
||||
config :logger,
|
||||
handle_otp_reports: false,
|
||||
handle_sasl_reports: false
|
||||
|
||||
config :lager, :error_logger_redirect, false
|
||||
config :lager, :error_logger_whitelist, []
|
||||
config :lager, :crash_log, false
|
||||
config :lager, :handlers, []
|
||||
|
||||
config :lager,
|
||||
handlers: [],
|
||||
extra_sinks: []
|
||||
|
|
|
@ -8,7 +8,7 @@ defmodule FarmbotExt.AMQP.AutoSyncTransport do
|
|||
}
|
||||
|
||||
alias FarmbotExt.AMQP.ConnectionWorker
|
||||
alias FarmbotExt.API.EagerLoader
|
||||
alias FarmbotExt.API.{Preloader, EagerLoader}
|
||||
|
||||
require Logger
|
||||
require FarmbotCore.Logger
|
||||
|
@ -23,8 +23,23 @@ defmodule FarmbotExt.AMQP.AutoSyncTransport do
|
|||
}
|
||||
|
||||
@exchange "amq.topic"
|
||||
@known_kinds ~w(
|
||||
Device
|
||||
FarmEvent
|
||||
FarmwareEnv
|
||||
FarmwareInstallation
|
||||
FbosConfig
|
||||
FirmwareConfig
|
||||
Peripheral
|
||||
PinBinding
|
||||
Point
|
||||
Regimen
|
||||
Sensor
|
||||
Sequence
|
||||
Tool
|
||||
)
|
||||
|
||||
defstruct [:conn, :chan, :jwt]
|
||||
defstruct [:conn, :chan, :jwt, :preloaded]
|
||||
alias __MODULE__, as: State
|
||||
|
||||
@doc false
|
||||
|
@ -35,7 +50,7 @@ defmodule FarmbotExt.AMQP.AutoSyncTransport do
|
|||
def init(args) do
|
||||
Process.flag(:sensitive, true)
|
||||
jwt = Keyword.fetch!(args, :jwt)
|
||||
{:ok, %State{conn: nil, chan: nil, jwt: jwt}, 1000}
|
||||
{:ok, %State{conn: nil, chan: nil, jwt: jwt, preloaded: false}, 1000}
|
||||
end
|
||||
|
||||
def terminate(reason, state) do
|
||||
|
@ -44,7 +59,12 @@ defmodule FarmbotExt.AMQP.AutoSyncTransport do
|
|||
if state.chan, do: AMQP.Channel.close(state.chan)
|
||||
end
|
||||
|
||||
def handle_info(:timeout, state) do
|
||||
def handle_info(:timeout, %{preloaded: false} = state) do
|
||||
:ok = Preloader.preload_all()
|
||||
{:noreply, %{state | preloaded: true}, 0}
|
||||
end
|
||||
|
||||
def handle_info(:timeout, %{preloaded: true} = state) do
|
||||
jwt = state.jwt
|
||||
bot = jwt.bot
|
||||
auto_sync = bot <> "_auto_sync"
|
||||
|
@ -85,15 +105,21 @@ defmodule FarmbotExt.AMQP.AutoSyncTransport do
|
|||
|
||||
def handle_info({:basic_deliver, payload, %{routing_key: key}}, state) do
|
||||
device = state.jwt.bot
|
||||
data = JSON.decode!(payload)
|
||||
label = data["args"]["label"]
|
||||
|
||||
case String.split(key, ".") do
|
||||
["bot", ^device, "sync", asset_kind, id_str] ->
|
||||
["bot", ^device, "sync", asset_kind, id_str] when asset_kind in @known_kinds ->
|
||||
asset_kind = Module.concat([Farmbot, Asset, asset_kind])
|
||||
data = JSON.decode!(payload)
|
||||
id = data["id"] || String.to_integer(id_str)
|
||||
params = data["body"]
|
||||
label = data["args"]["label"]
|
||||
handle_asset(asset_kind, label, id, params, state)
|
||||
:ok = handle_asset(asset_kind, label, id, params, state)
|
||||
|
||||
_ ->
|
||||
Logger.info("ignoring router: #{key}")
|
||||
json = JSON.encode!(%{args: %{label: label}, kind: "rpc_ok"})
|
||||
:ok = Basic.publish(state.chan, @exchange, "bot.#{device}.from_device", json)
|
||||
{:noreply, state}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -128,27 +154,23 @@ defmodule FarmbotExt.AMQP.AutoSyncTransport do
|
|||
:ok
|
||||
|
||||
auto_sync? ->
|
||||
if Code.ensure_loaded?(asset_kind) do
|
||||
case Repo.get_by(asset_kind, id: id) do
|
||||
nil ->
|
||||
struct(asset_kind)
|
||||
|> asset_kind.changeset(params)
|
||||
|> Repo.insert!()
|
||||
case Repo.get_by(asset_kind, id: id) do
|
||||
nil ->
|
||||
struct(asset_kind)
|
||||
|> asset_kind.changeset(params)
|
||||
|> Repo.insert!()
|
||||
|
||||
asset ->
|
||||
asset_kind.changeset(asset, params)
|
||||
|> Repo.update!()
|
||||
end
|
||||
asset ->
|
||||
asset_kind.changeset(asset, params)
|
||||
|> Repo.update!()
|
||||
end
|
||||
|
||||
:ok
|
||||
|
||||
true ->
|
||||
if Code.ensure_loaded?(asset_kind) do
|
||||
asset = Repo.get_by(asset_kind, id: id) || struct(asset_kind)
|
||||
changeset = asset_kind.changeset(asset, params)
|
||||
:ok = EagerLoader.cache(changeset)
|
||||
else
|
||||
:ok
|
||||
end
|
||||
asset = Repo.get_by(asset_kind, id: id) || struct(asset_kind)
|
||||
changeset = asset_kind.changeset(asset, params)
|
||||
:ok = EagerLoader.cache(changeset)
|
||||
end
|
||||
|
||||
device = state.jwt.bot
|
|
@ -1,4 +1,4 @@
|
|||
defmodule FarmbotExt.Bootstrap.APITask do
|
||||
defmodule FarmbotExt.API.Preloader do
|
||||
@moduledoc """
|
||||
Task to ensure Farmbot has synced:
|
||||
* FarmbotCore.Asset.Device
|
||||
|
@ -17,18 +17,12 @@ defmodule FarmbotExt.Bootstrap.APITask do
|
|||
Asset.Sync
|
||||
}
|
||||
|
||||
def child_spec(_) do
|
||||
%{
|
||||
id: __MODULE__,
|
||||
start: {__MODULE__, :sync_all, []},
|
||||
type: :worker,
|
||||
restart: :transient,
|
||||
shutdown: 500
|
||||
}
|
||||
end
|
||||
|
||||
@doc false
|
||||
def sync_all() do
|
||||
@doc """
|
||||
Syncronous call to sync or preload assets.
|
||||
Starts with `group_0` to check if `auto_sync` is enabled. If it is,
|
||||
actually sync all resources. If it is not, preload all resources.
|
||||
"""
|
||||
def preload_all() do
|
||||
sync_changeset = API.get_changeset(Sync)
|
||||
sync = Changeset.apply_changes(sync_changeset)
|
||||
|
||||
|
@ -45,8 +39,6 @@ defmodule FarmbotExt.Bootstrap.APITask do
|
|||
|
||||
:ok = maybe_auto_sync(sync_changeset, auto_sync_change || Asset.fbos_config().auto_sync)
|
||||
end
|
||||
|
||||
:ignore
|
||||
end
|
||||
|
||||
# When auto_sync is enabled, do the full sync.
|
|
@ -10,7 +10,6 @@ defmodule FarmbotExt.Bootstrap.Supervisor do
|
|||
children = [
|
||||
FarmbotExt.API.EagerLoader.Supervisor,
|
||||
FarmbotExt.API.DirtyWorker.Supervisor,
|
||||
FarmbotExt.Bootstrap.APITask,
|
||||
FarmbotExt.AMQP.Supervisor,
|
||||
FarmbotExt.API.ImageUploader
|
||||
]
|
|
@ -23,14 +23,14 @@ config :farmbot_core, FarmbotCore.Asset.Repo,
|
|||
|
||||
config :farmbot, FarmbotOS.Init.Supervisor,
|
||||
init_children: [
|
||||
FarmbotOS.TTYDetector,
|
||||
FarmbotOS.FirmwareTTYDetector,
|
||||
FarmbotOS.Platform.Host.Configurator
|
||||
]
|
||||
|
||||
config :farmbot,
|
||||
ecto_repos: [FarmbotCore.Config.Repo, FarmbotCore.Logger.Repo, FarmbotCore.Asset.Repo]
|
||||
|
||||
config :farmbot, FarmbotOS.TTYDetector,
|
||||
config :farmbot, FarmbotOS.FirmwareTTYDetector,
|
||||
expected_names: [
|
||||
System.get_env("FARMBOT_TTY")
|
||||
]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule FarmbotCore.FirmwareEstopTimer do
|
||||
defmodule FarmbotOS.FirmwareEstopTimer do
|
||||
@moduledoc """
|
||||
Process that wraps a `Process.send_after/3` call.
|
||||
When `:timeout` is received, a `fatal_email` log message will be
|
|
@ -1,9 +1,10 @@
|
|||
defmodule FarmbotCore.FirmwareSideEffects do
|
||||
defmodule FarmbotOS.FirmwareSideEffects do
|
||||
@moduledoc "Handles firmware data and syncing it with BotState."
|
||||
@behaviour FarmbotFirmware.SideEffects
|
||||
require Logger
|
||||
require FarmbotCore.Logger
|
||||
alias FarmbotCore.{Asset, BotState, FirmwareEstopTimer}
|
||||
alias FarmbotCore.{Asset, BotState}
|
||||
alias FarmbotOS.FirmwareEstopTimer
|
||||
|
||||
def handle_position(x: x, y: y, z: z) do
|
||||
:ok = BotState.set_position(x, y, z)
|
|
@ -1,4 +1,4 @@
|
|||
defmodule FarmbotOS.TTYDetector do
|
||||
defmodule FarmbotOS.FirmwareTTYDetector do
|
||||
use GenServer
|
||||
require Logger
|
||||
require FarmbotCore.Logger
|
|
@ -47,7 +47,7 @@ defmodule FarmbotOS.Init.FSCheckup do
|
|||
File.rm_rf(fw)
|
||||
end
|
||||
|
||||
init_logger_backend_ecto()
|
||||
init_logger_backend_sqlite()
|
||||
:ok
|
||||
|
||||
err ->
|
||||
|
@ -57,7 +57,7 @@ defmodule FarmbotOS.Init.FSCheckup do
|
|||
end
|
||||
end
|
||||
|
||||
defp init_logger_backend_ecto do
|
||||
defp init_logger_backend_sqlite do
|
||||
Logger.flush()
|
||||
|
||||
try do
|
||||
|
|
|
@ -11,7 +11,7 @@ defmodule FarmbotOS.Init.Supervisor do
|
|||
children =
|
||||
(config[:init_children] || []) ++
|
||||
[
|
||||
{FarmbotOS.Init.FSCheckup, []}
|
||||
FarmbotOS.Init.FSCheckup
|
||||
]
|
||||
|
||||
Supervisor.init(children, strategy: :one_for_all)
|
||||
|
|
|
@ -48,6 +48,7 @@ defmodule FarmbotOS.MixProject do
|
|||
# Farmbot stuff
|
||||
{:farmbot_core, path: "../farmbot_core", env: Mix.env()},
|
||||
{:farmbot_ext, path: "../farmbot_ext", env: Mix.env()},
|
||||
{:farmbot_firmware, path: "../farmbot_firmware", env: Mix.env()},
|
||||
|
||||
# Nerves stuff.
|
||||
{:nerves, "~> 1.3", runtime: false},
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
|
||||
"cors_plug": {:hex, :cors_plug, "2.0.0", "238ddb479f92b38f6dc1ae44b8d81f0387f9519101a6da442d543ab70ee0e482", [:mix], [{:plug, "~> 1.3 or ~> 1.4 or ~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
|
||||
"decimal": {:hex, :decimal, "1.6.0", "bfd84d90ff966e1f5d4370bdd3943432d8f65f07d3bab48001aebd7030590dcc", [:mix], [], "hexpm"},
|
||||
"decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
|
||||
"dhcp_server": {:hex, :dhcp_server, "0.6.0", "6cc0cf110b8d112455f033ae49eda570e9aeeb42a2fd1c79cc437835ecaa0716", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.4", "71b42f5ee1b7628f3e3a6565f4617dfb02d127a0499ab3e72750455e986df001", [:mix], [{:erlex, "~> 0.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"distillery": {:hex, :distillery, "2.0.12", "6e78fe042df82610ac3fa50bd7d2d8190ad287d120d3cd1682d83a44e8b34dfb", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
|
|
|
@ -285,13 +285,7 @@ defmodule FarmbotOS.Platform.Target.Configurator.Router do
|
|||
case conn.body_params do
|
||||
%{"firmware_hardware" => hw} when hw in ["arduino", "farmduino", "farmduino_k14"] ->
|
||||
update_config_value(:string, "settings", "firmware_hardware", hw)
|
||||
|
||||
if Application.get_env(:farmbot, :behaviour)[:firmware_handler] ==
|
||||
FarmbotFirmware.UartHandler do
|
||||
FarmbotCore.Logger.warn(1, "Updating #{hw} firmware is broke!!!!!!")
|
||||
# /shrug?
|
||||
# Farmbot.Firmware.UartHandler.Update.force_update_firmware(hw)
|
||||
end
|
||||
raise("configure firmware?")
|
||||
|
||||
redir(conn, "/credentials")
|
||||
|
||||
|
|
Loading…
Reference in New Issue