Config + dead code cleanup

pull/974/head
Connor Rigby 2018-11-05 08:18:26 -08:00
parent b3f1369a77
commit 3b8f8d591f
No known key found for this signature in database
GPG Key ID: 29A88B24B70456E0
16 changed files with 117 additions and 234 deletions

1
.gitignore vendored
View File

@ -55,3 +55,4 @@ RELEASE_NOTES
.elixir_ls
nerves-hub
*.pem
*.db

View File

@ -34,6 +34,7 @@ clean: clean_other_branch
rm -rf $$project/erl_crash.dump ; \
rm -rf $$project/.*.sqlite3* ; \
rm -rf $$project/*.sqlite3* ; \
rm -rf $$project/*.db ; \
rm -rf $$project/_build ; \
rm -rf $$project/deps ; \
rm -rf $$project/priv/*.so ; \

47
TODO.md
View File

@ -1,47 +0,0 @@
# FarmbotNG
Restructure of FarmbotOS to fix network and log errors.
# Things that still need migrating
* CeleryScript
* Scheduling
* Integration with `farmbot_core` somehow. (`@behaviour` maybe?)
* Farmware
* Error handling.
* Avoid factory resetting at all costs
* Where to put factory reset code? `farmbot_os` i guess?
* how to handle lower deps crashing?
* http syncing
# Things that have been migrated
* asset storage -> `farmbot_core`
* farmbot_firmware -> `farmbot_core`
* logging
* storage -> `farmbot_core`
* uploading -> `farmbot_ext`
* bot state management (partially)
* global state -> `farmbot_core`
* real time updating -> `farmbot_ext`
* configuration (partially) -> `farmbot_core`
* farm_events -> `farmbot_core`
* regimens -> `farmbot_core`
* authorization -> `farmbot_ext`
* amqp -> `farmbot_ext`
* http client -> `farmbot_ext`
* auto sync messages -> `farmbot_ext`
* Easter Eggs -> `farmbot_os` might move to `farmbot_ext`
* OTA Updates -> `farmbot_os`
* Networking -> `farmbot_os`
* System things -> `farmbot_os`
* System info -> `farmbot_os`
* Asset registry
* pin bindings -> `farmbot_core`
* led system -> `farmbot_os` + `farmbot_core`* C
* CI
# Things i am unsure about
* CeleryScript - Has both network _and_ core requirements.
* Farmware - Same
* database migrations might have been borked/need attention for upgrading production devices.
* Some early logs may need to be cleaned up.
* CI

View File

@ -1,10 +1,22 @@
use Mix.Config
# config :logger,
# handle_otp_reports: true,
# handle_sasl_reports: true
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmEvent,
checkup_time_ms: 10_000
config :ecto, json_library: Farmbot.JSON
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmwareInstallation,
error_retry_time_ms: 30_000,
install_dir: "/tmp/farmware"
config :farmbot_core, Farmbot.AssetMonitor,
checkup_time_ms: 30_000
config :farmbot_core,
expected_fw_versions: ["6.4.2.F", "6.4.2.R", "6.4.2.G"],
default_server: "https://my.farm.bot",
default_currently_on_beta:
String.contains?(to_string(:os.cmd('git rev-parse --abbrev-ref HEAD')), "beta"),
firmware_io_logs: false,
farm_event_debug_log: false
# Configure Farmbot Behaviours.
config :farmbot_core, :behaviour,
@ -14,48 +26,6 @@ config :farmbot_core, :behaviour,
celery_script_io_layer: Farmbot.Core.CeleryScript.StubIOLayer,
json_parser: Farmbot.JSON.JasonParser
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmEvent, checkup_time_ms: 10_000
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmwareInstallation,
error_retry_time_ms: 30_000,
install_dir: "/tmp/farmware"
config :farmbot_core, Farmbot.AssetMonitor, checkup_time_ms: 30_000
if Mix.env() == :test do
config :farmbot_core, :behaviour,
celery_script_io_layer: Farmbot.TestSupport.CeleryScript.TestIOLayer
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmEvent, checkup_time_ms: 1000
# must be lower than other timers
# To ensure other timers have time to timeout
config :farmbot_core, Farmbot.AssetMonitor, checkup_time_ms: 500
end
config :farmbot_core,
ecto_repos: [Farmbot.Config.Repo, Farmbot.Logger.Repo, Farmbot.Asset.Repo],
expected_fw_versions: ["6.4.2.F", "6.4.2.R", "6.4.2.G"],
default_server: "https://my.farm.bot",
default_currently_on_beta:
String.contains?(to_string(:os.cmd('git rev-parse --abbrev-ref HEAD')), "beta"),
firmware_io_logs: false,
farm_event_debug_log: false
config :farmbot_core, Farmbot.Config.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: ".#{Mix.env()}_configs.sqlite3",
priv: "priv/config"
config :farmbot_core, Farmbot.Logger.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: ".#{Mix.env()}_logs.sqlite3",
priv: "priv/logger"
config :farmbot_core, Farmbot.Asset.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: ".#{Mix.env()}_assets.sqlite3",
priv: "priv/asset"
import_config "ecto.exs"
import_config "logger.exs"
import_config "#{Mix.env()}.exs"

View File

View File

@ -0,0 +1,23 @@
use Mix.Config
config :ecto, json_library: Farmbot.JSON
config :farmbot_core,
ecto_repos: [Farmbot.Config.Repo, Farmbot.Logger.Repo, Farmbot.Asset.Repo]
config :farmbot_core, Farmbot.Config.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: "config.#{Mix.env()}.db",
priv: "priv/config"
config :farmbot_core, Farmbot.Logger.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: "logger.#{Mix.env()}.db",
priv: "priv/logger"
config :farmbot_core, Farmbot.Asset.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: "asset.#{Mix.env()}.db",
priv: "priv/asset"

View File

@ -0,0 +1,5 @@
use Mix.Config
# config :logger,
# handle_otp_reports: true,
# handle_sasl_reports: true

View File

@ -0,0 +1,10 @@
use Mix.Config
config :farmbot_core, :behaviour,
celery_script_io_layer: Farmbot.TestSupport.CeleryScript.TestIOLayer
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmEvent, checkup_time_ms: 1000
# must be lower than other timers
# To ensure other timers have time to timeout
config :farmbot_core, Farmbot.AssetMonitor, checkup_time_ms: 500

View File

@ -93,6 +93,5 @@ defmodule Farmbot.BotState.McuParams do
:encoder_invert_x,
:encoder_missed_steps_max_x,
:movement_invert_motor_y,
]
end

View File

@ -1,7 +0,0 @@
defmodule Farmbot.EctoTypes.JSONType do
@behaviour Ecto.Type
def type, do: :json
def cast(any), do: {:ok, any}
def load(value), do: Farmbot.JSON.decode(value)
def dump(value), do: Farmbot.JSON.encode(value)
end

View File

@ -1,49 +0,0 @@
defmodule Farmbot.EctoTypes.ModuleType do
@moduledoc """
Custom Ecto.Type for changing a string to a module.
"""
defmacro __using__(opts) do
mods = Keyword.fetch!(opts, :valid_mods)
quote do
@valid_short_strs unquote(mods)
@valid_mods Enum.map(unquote(mods), fn(mod) ->
Module.concat([Farmbot, Asset, mod])
end)
@moduledoc """
Custom Ecto.Type for changing a string field to one of
#{inspect(@valid_short_strs)}
"""
@behaviour Ecto.Type
def type, do: :string
def cast(exp) do
do_cast(exp)
end
def do_cast(string) when is_binary(string), do: {:ok, string}
def do_cast(module) when is_atom(module) do
if match?(<<"Elixir.", _::binary>>, to_string(module)) do
module
|> Module.split()
|> List.last()
|> (fn mod -> {:ok, mod} end).()
else
:error
end
end
def load(exp) do
{:ok, exp}
end
def dump(exp) do
{:ok, Module.concat([Farmbot, Asset, exp]) |> to_string()}
end
end
end
end

View File

@ -1,17 +0,0 @@
defmodule Farmbot.EctoTypes.TermType do
@moduledoc "Encodes/decodes data via the Erlang Term Format"
@behaviour Ecto.Type
def type, do: :text
def cast(binary) when is_binary(binary) do
{:ok, :erlang.binary_to_term(binary)}
end
def cast(term) do
{:ok, term}
end
def load(binary) when is_binary(binary), do: {:ok, :erlang.binary_to_term(binary)}
def dump(term), do: {:ok, :erlang.term_to_binary(term)}
end

View File

@ -1,66 +1,5 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# Stop lager redirecting :error_logger messages
config :lager, :error_logger_redirect, false
# Stop lager removing Logger's :error_logger handler
config :lager, :error_logger_whitelist, []
# Stop lager writing a crash log
config :lager, :crash_log, false
# Use LagerLogger as lager's only handler.
config :lager, :handlers, []
config :ssl, protocol_version: :"tlsv1.2"
config :ecto, json_library: Farmbot.JSON
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmEvent, checkup_time_ms: 10_000
config :farmbot_core, Farmbot.AssetMonitor, checkup_time_ms: 30_000
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmwareInstallation,
error_retry_time_ms: 30_000,
install_dir: "/tmp/farmware"
config :farmbot_core, :behaviour,
firmware_handler: Farmbot.Firmware.StubHandler,
leds_handler: Farmbot.Leds.StubHandler,
pin_binding_handler: Farmbot.PinBinding.StubHandler,
celery_script_io_layer: Farmbot.Core.CeleryScript.StubIOLayer,
json_parser: Farmbot.JSON.JasonParser
config :farmbot_core,
ecto_repos: [Farmbot.Config.Repo, Farmbot.Logger.Repo, Farmbot.Asset.Repo],
expected_fw_versions: ["6.4.0.F", "6.4.0.R", "6.4.0.G"],
default_server: "https://my.farm.bot",
default_currently_on_beta:
String.contains?(to_string(:os.cmd('git rev-parse --abbrev-ref HEAD')), "beta"),
firmware_io_logs: false,
farm_event_debug_log: false
config :farmbot_core, Farmbot.Config.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: ".#{Mix.env()}_configs.sqlite3",
priv: "../farmbot_core/priv/config"
config :farmbot_core, Farmbot.Logger.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: ".#{Mix.env()}_logs.sqlite3",
priv: "../farmbot_core/priv/logger"
config :farmbot_core, Farmbot.Asset.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: ".#{Mix.env()}_assets.sqlite3",
priv: "../farmbot_core/priv/asset"
config :farmbot_ext, :behaviour, authorization: Farmbot.Bootstrap.Authorization
config :farmbot_ext,
ecto_repos: [Farmbot.Config.Repo, Farmbot.Logger.Repo, Farmbot.Asset.Repo]
import_config "ecto.exs"
import_config "farmbot_core.exs"
import_config "lagger.exs"

View File

@ -0,0 +1,24 @@
use Mix.Config
config :farmbot_ext,
ecto_repos: [Farmbot.Config.Repo, Farmbot.Logger.Repo, Farmbot.Asset.Repo]
config :ecto, json_library: Farmbot.JSON
config :farmbot_core, Farmbot.Config.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: "config.#{Mix.env()}.db",
priv: "../farmbot_core/priv/config"
config :farmbot_core, Farmbot.Logger.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: "logger.#{Mix.env()}.db",
priv: "../farmbot_core/priv/logger"
config :farmbot_core, Farmbot.Asset.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: "asset.#{Mix.env()}.db",
priv: "../farmbot_core/priv/asset"

View File

@ -0,0 +1,26 @@
use Mix.Config
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmEvent,
checkup_time_ms: 10_000
config :farmbot_core, Farmbot.AssetMonitor,
checkup_time_ms: 30_000
config :farmbot_core, Farmbot.AssetWorker.Farmbot.Asset.FarmwareInstallation,
error_retry_time_ms: 30_000,
install_dir: "/tmp/farmware"
config :farmbot_core, :behaviour,
firmware_handler: Farmbot.Firmware.StubHandler,
leds_handler: Farmbot.Leds.StubHandler,
pin_binding_handler: Farmbot.PinBinding.StubHandler,
celery_script_io_layer: Farmbot.Core.CeleryScript.StubIOLayer,
json_parser: Farmbot.JSON.JasonParser
config :farmbot_core,
ecto_repos: [Farmbot.Config.Repo, Farmbot.Logger.Repo, Farmbot.Asset.Repo],
expected_fw_versions: ["6.4.0.F", "6.4.0.R", "6.4.0.G"],
default_server: "https://my.farm.bot",
default_currently_on_beta:
String.contains?(to_string(:os.cmd('git rev-parse --abbrev-ref HEAD')), "beta"),
firmware_io_logs: false,
farm_event_debug_log: false

View File

@ -0,0 +1,5 @@
use Mix.Config
config :lager, :error_logger_redirect, false
config :lager, :error_logger_whitelist, []
config :lager, :crash_log, false
config :lager, :handlers, []