Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only open and complete resources #98

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,39 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationConsumer do
message
end

defp write_to_hydration_cache(
message = %Broadway.Message{
data: %{
internal_resource: internal_resource,
metadata: %{"state" => state, "visibility" => visibility}
}
},
cache_version
)
when internal_resource in ["EphemeraFolder"] and state == ["complete"] and
visibility == ["open"] do
# store in HydrationCache:
# - data (blob) - this is the record
# - cache_order (datetime) - this is our own new timestamp for this table
# - cache_version (this only changes manually, we have to hold onto it as state)
# - record_id (varchar) - the figgy UUID
# - source_cache_order (datetime) - the figgy updated_at
{:ok, response} =
IndexingPipeline.write_hydration_cache_entry(%{
cache_version: cache_version,
record_id: message.data.id,
source_cache_order: message.data.updated_at,
data: message.data |> Map.from_struct() |> Map.delete(:__meta__)
})

{:ok, response}
end

defp write_to_hydration_cache(
message = %Broadway.Message{data: %{internal_resource: internal_resource}},
cache_version
)
when internal_resource in ["EphemeraFolder", "EphemeraTerm"] do
when internal_resource in ["EphemeraTerm"] do
# store in HydrationCache:
# - data (blob) - this is the record
# - cache_order (datetime) - this is our own new timestamp for this table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,43 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationConsumerTest do
alias DpulCollections.IndexingPipeline.Figgy

describe "Figgy.HydrationConsumer" do
test "handle_message/3 only writes EphemeraFolders and EphemeraTerms to the Figgy.HydrationCache" do
test "handle_message/3 only writes open and complete EphemeraFolders and EphemeraTerms to the Figgy.HydrationCache" do
ephemera_folder_message = %Broadway.Message{
acknowledger: nil,
data: %Figgy.Resource{
id: "47276197-e223-471c-99d7-405c5f6c5285",
updated_at: ~U[2018-03-09 20:19:34.486004Z],
internal_resource: "EphemeraFolder"
internal_resource: "EphemeraFolder",
metadata: %{
"state" => ["complete"],
"visibility" => ["open"]
}
}
}

pending_ephemera_folder_message = %Broadway.Message{
acknowledger: nil,
data: %Figgy.Resource{
id: "47276197-e223-471c-99d7-405c5f6c5285",
updated_at: ~U[2018-03-09 20:19:34.486004Z],
internal_resource: "EphemeraFolder",
metadata: %{
"state" => ["pending"],
"visibility" => ["open"]
}
}
}

restricted_ephemera_folder_message = %Broadway.Message{
acknowledger: nil,
data: %Figgy.Resource{
id: "47276197-e223-471c-99d7-405c5f6c5285",
updated_at: ~U[2018-03-09 20:19:34.486004Z],
internal_resource: "EphemeraFolder",
metadata: %{
"state" => ["complete"],
"visibility" => ["restricted"]
}
}
}

Expand All @@ -34,7 +64,13 @@ defmodule DpulCollections.IndexingPipeline.Figgy.HydrationConsumerTest do

Figgy.HydrationConsumer.handle_batch(
nil,
[ephemera_folder_message, ephemera_term_message, scanned_resource_message],
[
ephemera_folder_message,
pending_ephemera_folder_message,
restricted_ephemera_folder_message,
ephemera_term_message,
scanned_resource_message
],
nil,
%{cache_version: 0}
)
Expand Down
Loading