fix syncing

pull/261/head
connor rigby 2017-03-03 07:49:01 -08:00
parent f490480576
commit daa56cd3bd
4 changed files with 62 additions and 35 deletions

View File

@ -145,9 +145,15 @@ defmodule Farmbot.BotState do
@doc """
Sets the bots state of weather we need to sync or not.
"""
@spec set_sync_msg(String.t) :: :ok
def set_sync_msg(string) do
string = String.Casing.downcase(string)
GenServer.cast(Configuration, {:update_info, :sync_status, string})
end
@type sync_msg :: Configuration.sync_msg
@spec set_sync_msg(sync_msg) :: :ok
def set_sync_msg(sync_msg)
def set_sync_msg(:sync_now = thing),
do: GenServer.cast(Configuration, {:update_info, :sync_status, thing})
def set_sync_msg(:syncing = thing),
do: GenServer.cast(Configuration, {:update_info, :sync_status, thing})
def set_sync_msg(:sync_error = thing),
do: GenServer.cast(Configuration, {:update_info, :sync_status, thing})
def set_sync_msg(:unknown = thing),
do: GenServer.cast(Configuration, {:update_info, :sync_status, thing})
end

View File

@ -29,10 +29,13 @@ defmodule Farmbot.BotState.Configuration do
target: "loading...",
private_ip: nil,
commit: "loading...",
sync_status: "sync now"
sync_status: :sync_now
}
]
@typedoc """
The message for the sync button to display
"""
@type sync_msg :: :sync_now | :syncing | :sync_error | :unknown
@type args
:: %{compat_version: integer,
target: String.t,
@ -50,7 +53,8 @@ defmodule Farmbot.BotState.Configuration do
steps_per_mm_z: integer,
distance_mm_x: integer,
distance_mm_y: integer,
distance_mm_z: integer
distance_mm_z: integer,
sync_status: sync_msg
},
informational_settings: map # TODO type this
}
@ -64,7 +68,7 @@ defmodule Farmbot.BotState.Configuration do
target: args.target,
private_ip: "loading...",
commit: args.commit,
sync_status: "sync now"
sync_status: :sync_now
}
}
{:ok, user_env} = get_config("user_env")

View File

@ -104,7 +104,7 @@ defmodule Farmbot.Sync do
{:ok, %{required(atom) => [map] | map}} | {:error, term}
# This is the most complex method in all of this application.
def sync do
Farmbot.BotState.set_sync_msg "syncing"
Farmbot.BotState.set_sync_msg :syncing
# TODO(Connor) Should probably move this to its own function
# but right now its only one thing
Logger.info ">> is checking for images to be uploaded."
@ -123,12 +123,27 @@ defmodule Farmbot.Sync do
:: {:ok, %{required(atom) => [map] | map}} | {:error, term}
defp sync_some(some) do
# TODO(Connor) this is incomplete
blerp = Enum.map(some, fn(cached_thing) ->
cached_thing.syncable
blerp = Enum.map(some, fn({syncable, _cached_thing}) ->
to_module_syncable(syncable)
end)
sync_all(blerp)
end
# ignore this pls
@spec to_module_syncable(atom) :: atom
defp to_module_syncable(:devices), do: Database.Device
defp to_module_syncable(:peripherals), do: Database.Peripheral
defp to_module_syncable(:plants), do: Database.Plant
defp to_module_syncable(:points), do: Database.Point
defp to_module_syncable(:regimens), do: Database.Regimen
defp to_module_syncable(:sequences), do: Database.Sequence
defp to_module_syncable(:tool_bays), do: Database.ToolBay
defp to_module_syncable(:tool_slots), do: Database.ToolSlot
defp to_module_syncable(:tools), do: Database.Tool
defp to_module_syncable(:users), do: Database.User
defp to_module_syncable(:farm_events), do: Database.FarmEvent
@spec sync_all(atom)
:: {:ok, %{required(atom) => [map] | map}} | {:error, term}
defp sync_all(list_of_syncables \\ nil) do
@ -202,11 +217,11 @@ defmodule Farmbot.Sync do
# if there are no errors, return success, if not, return the fails
if Enum.empty?(fails) do
Logger.info ">> is synced!", type: :success
Farmbot.BotState.set_sync_msg "synced"
Farmbot.BotState.set_sync_msg :synced
{:ok, success}
else
Logger.error ">> encountered errors syncing: #{inspect fails}"
Farmbot.BotState.set_sync_msg "sync error"
Farmbot.BotState.set_sync_msg :sync_error
{:error, fails}
end
end

View File

@ -1,23 +1,25 @@
{
"compilerOptions": {
"lib": [
"es7",
"dom"
],
"target": "es5",
"module": "commonjs",
"jsx": "react",
"noImplicitAny": true,
"experimentalDecorators": true,
"allowUnreachableCode": false,
"strictNullChecks": true,
"sourceMap": true,
"noFallthroughCasesInSwitch": true
},
"exclude": [
"node_modules",
"typings"
],
"compileOnSave": false,
"buildOnSave": false
"compilerOptions": {
"lib": [
"es7",
"dom"
],
"target": "es5",
"module": "commonjs",
"jsx": "react",
"noImplicitAny": true,
"experimentalDecorators": true,
"allowUnreachableCode": false,
"strictNullChecks": true,
"sourceMap": true,
"noFallthroughCasesInSwitch": true
},
"exclude": [
"node_modules",
"typings",
"_build",
"nerves"
],
"compileOnSave": false,
"buildOnSave": false
}