don't error out
This commit is contained in:
parent
4e8ee48cff
commit
4e7e95a17e
|
@ -59,31 +59,43 @@ def maybe_bulk_post(data, type) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def put(%Activity{} = activity) do
|
def put(%Activity{} = activity) do
|
||||||
{:ok, _} =
|
with {:ok, _} <-
|
||||||
Elastix.Document.index(
|
Elastix.Document.index(
|
||||||
url(),
|
url(),
|
||||||
"activities",
|
"activities",
|
||||||
"activity",
|
"activity",
|
||||||
DocumentMappings.Activity.id(activity),
|
DocumentMappings.Activity.id(activity),
|
||||||
DocumentMappings.Activity.encode(activity)
|
DocumentMappings.Activity.encode(activity)
|
||||||
)
|
) do
|
||||||
|
|
||||||
activity
|
activity
|
||||||
|> Map.get(:object)
|
|> Map.get(:object)
|
||||||
|> Object.hashtags()
|
|> Object.hashtags()
|
||||||
|> Enum.map(fn x -> %{id: x, name: x, timestamp: DateTime.to_iso8601(DateTime.utc_now())} end)
|
|> Enum.map(fn x ->
|
||||||
|
%{id: x, name: x, timestamp: DateTime.to_iso8601(DateTime.utc_now())}
|
||||||
|
end)
|
||||||
|> bulk_post(:hashtags)
|
|> bulk_post(:hashtags)
|
||||||
|
else
|
||||||
|
{:error, %{reason: err}} ->
|
||||||
|
Logger.error("Could not put activity: #{err}")
|
||||||
|
:skipped
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def put(%User{} = user) do
|
def put(%User{} = user) do
|
||||||
{:ok, _} =
|
with {:ok, _} <-
|
||||||
Elastix.Document.index(
|
Elastix.Document.index(
|
||||||
url(),
|
url(),
|
||||||
"users",
|
"users",
|
||||||
"user",
|
"user",
|
||||||
DocumentMappings.User.id(user),
|
DocumentMappings.User.id(user),
|
||||||
DocumentMappings.User.encode(user)
|
DocumentMappings.User.encode(user)
|
||||||
)
|
) do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
{:error, %{reason: err}} ->
|
||||||
|
Logger.error("Could not put user: #{err}")
|
||||||
|
:skipped
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_post(data, :activities) do
|
def bulk_post(data, :activities) do
|
||||||
|
@ -105,13 +117,22 @@ def bulk_post(data, :activities) do
|
||||||
end)
|
end)
|
||||||
|> List.flatten()
|
|> List.flatten()
|
||||||
|
|
||||||
{:ok, %{body: %{"errors" => false}}} =
|
with {:ok, %{body: %{"errors" => false}}} <-
|
||||||
Elastix.Bulk.post(
|
Elastix.Bulk.post(
|
||||||
url(),
|
url(),
|
||||||
d,
|
d,
|
||||||
index: "activities",
|
index: "activities",
|
||||||
type: "activity"
|
type: "activity"
|
||||||
)
|
) do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
{:error, %{reason: err}} ->
|
||||||
|
Logger.error("Could not bulk put activity: #{err}")
|
||||||
|
:skipped
|
||||||
|
{:ok, %{body: body}} ->
|
||||||
|
IO.inspect(body)
|
||||||
|
:skipped
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_post(data, :users) do
|
def bulk_post(data, :users) do
|
||||||
|
@ -126,12 +147,22 @@ def bulk_post(data, :users) do
|
||||||
end)
|
end)
|
||||||
|> List.flatten()
|
|> List.flatten()
|
||||||
|
|
||||||
|
with {:ok, %{body: %{"errors" => false}}} <-
|
||||||
Elastix.Bulk.post(
|
Elastix.Bulk.post(
|
||||||
url(),
|
url(),
|
||||||
d,
|
d,
|
||||||
index: "users",
|
index: "users",
|
||||||
type: "user"
|
type: "user"
|
||||||
)
|
) do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
{:error, %{reason: err}} ->
|
||||||
|
Logger.error("Could not bulk put users: #{err}")
|
||||||
|
:skipped
|
||||||
|
{:ok, %{body: body}} ->
|
||||||
|
IO.inspect(body)
|
||||||
|
:skipped
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_post(data, :hashtags) when is_list(data) do
|
def bulk_post(data, :hashtags) when is_list(data) do
|
||||||
|
@ -145,12 +176,22 @@ def bulk_post(data, :hashtags) when is_list(data) do
|
||||||
end)
|
end)
|
||||||
|> List.flatten()
|
|> List.flatten()
|
||||||
|
|
||||||
|
with {:ok, %{body: %{"errors" => false}}} <-
|
||||||
Elastix.Bulk.post(
|
Elastix.Bulk.post(
|
||||||
url(),
|
url(),
|
||||||
d,
|
d,
|
||||||
index: "hashtags",
|
index: "hashtags",
|
||||||
type: "hashtag"
|
type: "hashtag"
|
||||||
)
|
) do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
{:error, %{reason: err}} ->
|
||||||
|
Logger.error("Could not bulk put hashtags: #{err}")
|
||||||
|
:skipped
|
||||||
|
{:ok, %{body: body}} ->
|
||||||
|
IO.inspect(body)
|
||||||
|
:skipped
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def bulk_post(_, :hashtags), do: {:ok, nil}
|
def bulk_post(_, :hashtags), do: {:ok, nil}
|
||||||
|
|
Loading…
Reference in a new issue