Drilling down deeper into isolating stale data bug
parent
c5b40d9b6d
commit
3b256f14f6
|
@ -5,6 +5,7 @@ defmodule FarmbotCore.Asset.Private do
|
||||||
_are_ stored in Farmbot's database.
|
_are_ stored in Farmbot's database.
|
||||||
"""
|
"""
|
||||||
require Logger
|
require Logger
|
||||||
|
require FarmbotCore.Logger
|
||||||
|
|
||||||
alias FarmbotCore.{Asset.Repo,
|
alias FarmbotCore.{Asset.Repo,
|
||||||
Asset.Private.LocalMeta,
|
Asset.Private.LocalMeta,
|
||||||
|
@ -15,14 +16,28 @@ defmodule FarmbotCore.Asset.Private do
|
||||||
|
|
||||||
@doc "Lists `module` objects that still need to be POSTed to the API."
|
@doc "Lists `module` objects that still need to be POSTed to the API."
|
||||||
def list_local(module) do
|
def list_local(module) do
|
||||||
Repo.all(from(data in module, where: is_nil(data.id)))
|
list = Repo.all(from(data in module, where: is_nil(data.id)))
|
||||||
|
Enum.map(list, fn item ->
|
||||||
|
if module == FarmbotCore.Asset.Point do
|
||||||
|
msg = "list_local: Point#{item.id}.y = #{item.y || "nil"}"
|
||||||
|
FarmbotCore.Logger.info(3, msg)
|
||||||
|
end
|
||||||
|
item
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "Lists `module` objects that have a `local_meta` object"
|
@doc "Lists `module` objects that have a `local_meta` object"
|
||||||
def list_dirty(module) do
|
def list_dirty(module) do
|
||||||
table = table(module)
|
table = table(module)
|
||||||
q = from(lm in LocalMeta, where: lm.table == ^table, select: lm.asset_local_id)
|
q = from(lm in LocalMeta, where: lm.table == ^table, select: lm.asset_local_id)
|
||||||
Repo.all(from(data in module, join: lm in subquery(q)))
|
list = Repo.all(from(data in module, join: lm in subquery(q)))
|
||||||
|
Enum.map(list, fn item ->
|
||||||
|
if module == FarmbotCore.Asset.Point do
|
||||||
|
msg = "list_local: Point#{item.id}.y = #{item.y || "nil"}"
|
||||||
|
FarmbotCore.Logger.info(3, msg)
|
||||||
|
end
|
||||||
|
item
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def maybe_get_local_meta(asset, table) do
|
def maybe_get_local_meta(asset, table) do
|
||||||
|
|
|
@ -51,10 +51,6 @@ defmodule FarmbotExt.API.DirtyWorker do
|
||||||
end
|
end
|
||||||
|
|
||||||
def work(dirty, module) do
|
def work(dirty, module) do
|
||||||
if module == FarmbotCore.Asset.Point do
|
|
||||||
FarmbotCore.Logger.info(3, "#{__MODULE__} Point#{dirty.id}.y = #{dirty.y}")
|
|
||||||
end
|
|
||||||
|
|
||||||
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 ->
|
||||||
|
|
|
@ -32,11 +32,11 @@ defmodule FarmbotOS.SysCalls.ResourceUpdate do
|
||||||
"Weed" => "weed"
|
"Weed" => "weed"
|
||||||
}
|
}
|
||||||
|
|
||||||
def notify_user_of_updates(kind, params) do
|
def notify_user_of_updates(kind, params, id \\ nil) do
|
||||||
Enum.map(params, fn {k, v} ->
|
Enum.map(params, fn {k, v} ->
|
||||||
name = @friendly_names[kind] || kind
|
name = @friendly_names[kind] || kind
|
||||||
property = @friendly_names["#{k}"] || k
|
property = @friendly_names["#{k}"] || k
|
||||||
msg = "Setting #{name} #{property} to #{inspect(v)}"
|
msg = "Setting #{name} #{id} #{property} to #{inspect(v)}"
|
||||||
FarmbotCore.Logger.info(3, msg)
|
FarmbotCore.Logger.info(3, msg)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -53,7 +53,7 @@ defmodule FarmbotOS.SysCalls.ResourceUpdate do
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_resource(kind, id, params) when kind in @point_kinds do
|
def update_resource(kind, id, params) when kind in @point_kinds do
|
||||||
notify_user_of_updates(kind, params)
|
notify_user_of_updates(kind, params, id)
|
||||||
params = do_handlebars(params)
|
params = do_handlebars(params)
|
||||||
point_update_resource(kind, id, params)
|
point_update_resource(kind, id, params)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue