Begin debugging `clean_params`

qa/10.0.0
Rick Carlino 2020-05-15 20:11:37 -05:00
parent 70b5fb18bb
commit 02f16082b9
3 changed files with 9 additions and 10 deletions

View File

@ -7,7 +7,6 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
variable = unquote(Map.fetch!(args, :resource))
update = unquote(unpair(body, %{}))
# Go easy on the API...
Process.sleep(250)
case variable do
%AST{kind: :identifier} ->
args = Map.fetch!(variable, :args)
@ -49,7 +48,6 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
end
defp unpair([pair | rest], acc) do
IO.puts("TODO: Need to apply handlebars to `value`s.")
key = Map.fetch!(pair.args, :label)
val = Map.fetch!(pair.args, :value)
next_acc = Map.merge(acc, DotProps.create(key, val))

View File

@ -251,7 +251,7 @@ defmodule FarmbotCore.Asset do
end
def update_point(point, params) do
# TODO: RC 8 MAY 20202 - We need to hard refresh the point.
# TODO: RC 8 MAY 2020 - We need to hard refresh the point.
# The CSVM appears to be caching resources. This leads
# to problems when a user runs a sequence that has two
# MARK AS steps.
@ -259,6 +259,7 @@ defmodule FarmbotCore.Asset do
# by default, not a merge action.
# MORE NOTES: Mixed keys (symbol vs. string) will crash this FN.
# Let's just stringify everything...
IO.inspect(params, label: "===== ORIGINAL PARAMS")
new_meta = params[:meta] || params["meta"] || %{}
old_meta = point.meta || %{}
updated_meta = Map.merge(old_meta, new_meta)
@ -267,6 +268,7 @@ defmodule FarmbotCore.Asset do
|> Enum.map(fn {k, v} -> {"#{k}", v} end)
|> Map.new()
IO.inspect(clean_params, label: "=========== CLEAN PARAMS")
Repo.get_by(Point, id: point.id)
|> Point.changeset(clean_params)
|> Repo.update()

View File

@ -8,7 +8,7 @@ defmodule FarmbotExt.API.DirtyWorker do
require Logger
require FarmbotCore.Logger
use GenServer
@timeout 1500
@timeout 100
# these resources can't be accessed by `id`.
@singular [
@ -36,7 +36,7 @@ defmodule FarmbotExt.API.DirtyWorker do
@impl GenServer
def init(args) do
module = Keyword.fetch!(args, :module)
Process.send_after(self(), :do_work, 100)
Process.send_after(self(), :do_work, @timeout)
{:ok, %{module: module}}
end
@ -44,7 +44,9 @@ defmodule FarmbotExt.API.DirtyWorker do
def handle_info(:do_work, %{module: module} = state) do
(Private.list_dirty(module) ++ Private.list_local(module))
|> Enum.uniq()
|> Enum.map(fn dirty -> work(dirty, module) end)
|> Enum.map(fn dirty ->
work(dirty, module)
end)
Process.send_after(self(), :do_work, @timeout)
{:noreply, state}
@ -54,7 +56,6 @@ defmodule FarmbotExt.API.DirtyWorker do
case http_request(dirty, module) do
# Valid data
{:ok, %{status: s, body: body}} when s > 199 and s < 300 ->
FarmbotCore.Logger.error(2, "HTTP #{s} OK. #{inspect(body)}")
dirty |> module.changeset(body) |> handle_changeset(module)
# Invalid data
@ -81,8 +82,6 @@ defmodule FarmbotExt.API.DirtyWorker do
inspect(error)
}"
)
module
end
end
@ -100,7 +99,7 @@ defmodule FarmbotExt.API.DirtyWorker do
end)
|> Enum.join("\n")
Logger.error("Failed to sync: #{module} \n #{message}")
FarmbotCore.Logger.error(3, "Failed to sync: #{module} \n #{message}")
_ = Repo.delete!(data)
:ok
end