Begin debugging `clean_params`
parent
70b5fb18bb
commit
02f16082b9
|
@ -7,7 +7,6 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
|
||||||
variable = unquote(Map.fetch!(args, :resource))
|
variable = unquote(Map.fetch!(args, :resource))
|
||||||
update = unquote(unpair(body, %{}))
|
update = unquote(unpair(body, %{}))
|
||||||
# Go easy on the API...
|
# Go easy on the API...
|
||||||
Process.sleep(250)
|
|
||||||
case variable do
|
case variable do
|
||||||
%AST{kind: :identifier} ->
|
%AST{kind: :identifier} ->
|
||||||
args = Map.fetch!(variable, :args)
|
args = Map.fetch!(variable, :args)
|
||||||
|
@ -49,7 +48,6 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp unpair([pair | rest], acc) do
|
defp unpair([pair | rest], acc) do
|
||||||
IO.puts("TODO: Need to apply handlebars to `value`s.")
|
|
||||||
key = Map.fetch!(pair.args, :label)
|
key = Map.fetch!(pair.args, :label)
|
||||||
val = Map.fetch!(pair.args, :value)
|
val = Map.fetch!(pair.args, :value)
|
||||||
next_acc = Map.merge(acc, DotProps.create(key, val))
|
next_acc = Map.merge(acc, DotProps.create(key, val))
|
||||||
|
|
|
@ -251,7 +251,7 @@ defmodule FarmbotCore.Asset do
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_point(point, params) do
|
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
|
# The CSVM appears to be caching resources. This leads
|
||||||
# to problems when a user runs a sequence that has two
|
# to problems when a user runs a sequence that has two
|
||||||
# MARK AS steps.
|
# MARK AS steps.
|
||||||
|
@ -259,6 +259,7 @@ defmodule FarmbotCore.Asset do
|
||||||
# by default, not a merge action.
|
# by default, not a merge action.
|
||||||
# MORE NOTES: Mixed keys (symbol vs. string) will crash this FN.
|
# MORE NOTES: Mixed keys (symbol vs. string) will crash this FN.
|
||||||
# Let's just stringify everything...
|
# Let's just stringify everything...
|
||||||
|
IO.inspect(params, label: "===== ORIGINAL PARAMS")
|
||||||
new_meta = params[:meta] || params["meta"] || %{}
|
new_meta = params[:meta] || params["meta"] || %{}
|
||||||
old_meta = point.meta || %{}
|
old_meta = point.meta || %{}
|
||||||
updated_meta = Map.merge(old_meta, new_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)
|
|> Enum.map(fn {k, v} -> {"#{k}", v} end)
|
||||||
|> Map.new()
|
|> Map.new()
|
||||||
|
|
||||||
|
IO.inspect(clean_params, label: "=========== CLEAN PARAMS")
|
||||||
Repo.get_by(Point, id: point.id)
|
Repo.get_by(Point, id: point.id)
|
||||||
|> Point.changeset(clean_params)
|
|> Point.changeset(clean_params)
|
||||||
|> Repo.update()
|
|> Repo.update()
|
||||||
|
|
|
@ -8,7 +8,7 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
require Logger
|
require Logger
|
||||||
require FarmbotCore.Logger
|
require FarmbotCore.Logger
|
||||||
use GenServer
|
use GenServer
|
||||||
@timeout 1500
|
@timeout 100
|
||||||
|
|
||||||
# these resources can't be accessed by `id`.
|
# these resources can't be accessed by `id`.
|
||||||
@singular [
|
@singular [
|
||||||
|
@ -36,7 +36,7 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
@impl GenServer
|
@impl GenServer
|
||||||
def init(args) do
|
def init(args) do
|
||||||
module = Keyword.fetch!(args, :module)
|
module = Keyword.fetch!(args, :module)
|
||||||
Process.send_after(self(), :do_work, 100)
|
Process.send_after(self(), :do_work, @timeout)
|
||||||
{:ok, %{module: module}}
|
{:ok, %{module: module}}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,7 +44,9 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
def handle_info(:do_work, %{module: module} = state) do
|
def handle_info(:do_work, %{module: module} = state) do
|
||||||
(Private.list_dirty(module) ++ Private.list_local(module))
|
(Private.list_dirty(module) ++ Private.list_local(module))
|
||||||
|> Enum.uniq()
|
|> 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)
|
Process.send_after(self(), :do_work, @timeout)
|
||||||
{:noreply, state}
|
{:noreply, state}
|
||||||
|
@ -54,7 +56,6 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
case http_request(dirty, module) do
|
case http_request(dirty, module) do
|
||||||
# Valid data
|
# Valid data
|
||||||
{:ok, %{status: s, body: body}} when s > 199 and s < 300 ->
|
{: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)
|
dirty |> module.changeset(body) |> handle_changeset(module)
|
||||||
|
|
||||||
# Invalid data
|
# Invalid data
|
||||||
|
@ -81,8 +82,6 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
inspect(error)
|
inspect(error)
|
||||||
}"
|
}"
|
||||||
)
|
)
|
||||||
|
|
||||||
module
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
end)
|
end)
|
||||||
|> Enum.join("\n")
|
|> Enum.join("\n")
|
||||||
|
|
||||||
Logger.error("Failed to sync: #{module} \n #{message}")
|
FarmbotCore.Logger.error(3, "Failed to sync: #{module} \n #{message}")
|
||||||
_ = Repo.delete!(data)
|
_ = Repo.delete!(data)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue