Update docs for farmbot_ext otp app

pull/1087/head
Connor Rigby 2019-12-17 14:19:53 -08:00 committed by Connor Rigby
parent b6be227e27
commit 63fffcfc5d
11 changed files with 58 additions and 13 deletions

View File

@ -1,5 +1,7 @@
defmodule FarmbotExt.AMQP.ChannelSupervisor do
@moduledoc false
@moduledoc """
Supervises AMQP channels
"""
use Supervisor
alias FarmbotExt.JWT

View File

@ -1,9 +1,13 @@
defmodule FarmbotExt.AMQP.PingPongChannel do
@moduledoc """
This module provides an AMQP channel for
auto-sync messages from the FarmBot API.
SEE:
https://developer.farm.bot/docs/realtime-updates-auto-sync#section-example-auto-sync-subscriptions
AMQP channel responsible for responding to `ping` messages.
Simply echos the exact data received on the `ping` channel
onto the `pong` channel.
Also has a ~15-20 minute timer that will do an `HTTP` request
to `/api/device`. This refreshed the `last_seen_api` field which
is required for devices that have `auto_sync` enabled as with
that field enabled, the device would never do an HTTP request
"""
use GenServer
use AMQP

View File

@ -1,5 +1,7 @@
defmodule FarmbotExt.AMQP.Supervisor do
@moduledoc false
@moduledoc """
Supervises AMQP connections
"""
use Supervisor
import FarmbotCore.Config, only: [get_config_value: 3]

View File

@ -1,6 +1,9 @@
defmodule FarmbotExt.AMQP.TelemetryChannel do
@moduledoc """
Channel that dispatches telemetry messgaes out of the
DETS database.
"""
use GenServer
use AMQP

View File

@ -1,6 +1,9 @@
defmodule FarmbotExt.API do
alias FarmbotExt.{API, JWT}
@moduledoc """
Module where all Farmbot specific HTTP calls are done
"""
alias FarmbotExt.{API, JWT}
alias FarmbotCore.JSON
alias FarmbotCore.Asset.{
@ -10,10 +13,8 @@ defmodule FarmbotExt.API do
}
alias FarmbotCore.{BotState, BotState.JobProgress.Percent, Project}
require FarmbotCore.Logger
import FarmbotCore.Config, only: [get_config_value: 3]
use Tesla
alias Tesla.Multipart

View File

@ -1,4 +1,9 @@
defmodule FarmbotExt.API.DirtyWorker.Supervisor do
@moduledoc """
Responsible for supervising assets that will need to be
uploaded to the API via a `POST` or `PUT` request.
"""
use Supervisor
alias FarmbotExt.API.DirtyWorker
@ -22,10 +27,12 @@ defmodule FarmbotExt.API.DirtyWorker.Supervisor do
Tool
}
@doc false
def start_link(args) do
Supervisor.start_link(__MODULE__, args, name: __MODULE__)
end
@impl Supervisor
def init(_args) do
children = [
{DirtyWorker, Device},

View File

@ -1,4 +1,9 @@
defmodule FarmbotExt.API.EagerLoader.Supervisor do
@moduledoc """
Responsible for supervising all assets that need to be
eagerloaded
"""
use Supervisor
alias FarmbotExt.API.EagerLoader
@ -22,15 +27,18 @@ defmodule FarmbotExt.API.EagerLoader.Supervisor do
Tool
}
@doc false
def start_link(args) do
Supervisor.start_link(__MODULE__, args, name: __MODULE__)
end
@doc "Drop all cached assets"
def drop_all_cache() do
for {_, pid, _, _} <- Supervisor.which_children(FarmbotExt.API.EagerLoader.Supervisor),
do: GenServer.cast(pid, :drop)
end
@impl Supervisor
def init(_args) do
children = [
{EagerLoader, Device},

View File

@ -1,18 +1,25 @@
defmodule FarmbotExt.Bootstrap do
use GenServer
@moduledoc """
Task responsible for using
a token, secret, or password for logging into an account
"""
use GenServer
require Logger
alias FarmbotExt.{Bootstrap, Bootstrap.Authorization}
import FarmbotCore.Config, only: [update_config_value: 4, get_config_value: 3]
@doc false
def start_link(args) do
GenServer.start_link(__MODULE__, args, name: __MODULE__)
end
@impl GenServer
def init([]) do
{:ok, nil, 0}
end
@impl GenServer
def handle_info(:timeout, nil) do
email = get_config_value(:string, "authorization", "email")
server = get_config_value(:string, "authorization", "server")
@ -21,6 +28,8 @@ defmodule FarmbotExt.Bootstrap do
try_auth(email, server, password, secret)
end
# state machine implementation
@doc false
def try_auth(nil, _server, _password, _secret) do
{:noreply, nil, 5000}
end
@ -41,7 +50,6 @@ defmodule FarmbotExt.Bootstrap do
end
end
# TODO(Connor) - drop password and save secret here somehow.
def try_auth(email, server, password, _secret) do
Logger.debug("using password to auth")

View File

@ -9,15 +9,18 @@ defmodule FarmbotExt.Bootstrap.DropPasswordTask do
use GenServer
@doc false
def start_link(args, opts \\ [name: __MODULE__]) do
GenServer.start_link(__MODULE__, args, opts)
end
@impl GenServer
def init(_args) do
send(self(), :checkup)
{:ok, %{backoff: 5000, timer: nil}}
end
@impl GenServer
def handle_info(:checkup, state) do
email = get_config_value(:string, "authorization", "email")
password = get_config_value(:string, "authorization", "password")

View File

@ -1,11 +1,16 @@
defmodule FarmbotExt.Bootstrap.Supervisor do
@moduledoc """
Supervisor responsible for starting all
the tasks and processes that require authentication.
"""
use Supervisor
@doc "Start Bootstraped services."
@doc false
def start_link(args) do
Supervisor.start_link(__MODULE__, args, name: __MODULE__)
end
@impl Supervisor
def init([]) do
children = [
FarmbotExt.API.EagerLoader.Supervisor,

View File

@ -1,4 +1,6 @@
# DELETEME
# TODO(Connor) delete this one day.
# this will require defining farmbot specific encode/decode
# protocols for both of these structures
require Protocol
Protocol.derive(Jason.Encoder, FarmbotExt.JWT)
Protocol.derive(Jason.Encoder, FarmbotCeleryScript.AST)