Skip to content

Commit

Permalink
Update Put to use instance args
Browse files Browse the repository at this point in the history
  • Loading branch information
csutter committed May 28, 2024
1 parent 0ac7aa9 commit 056c25f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/models/publishing_api_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def synchronize
elsif sync?
log("sync")
Metrics::Exported.increment_counter(:documents_synced)
put_service.new(content_id, metadata, content:, payload_version:).call(content_id, metadata, content:, payload_version:)
put_service.new(content_id, metadata, content:, payload_version:).call
elsif desync?
log("desync (#{action_reason}))")
Metrics::Exported.increment_counter(:documents_desynced)
Expand Down
2 changes: 1 addition & 1 deletion app/services/discovery_engine/sync/put.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def initialize(
@client = client
end

def call(content_id, metadata, content: "", payload_version: nil)
def call
with_locked_document(content_id, payload_version:) do
if outdated_payload_version?(content_id, payload_version:)
log(
Expand Down
24 changes: 13 additions & 11 deletions spec/services/discovery_engine/sync/put_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
RSpec.describe DiscoveryEngine::Sync::Put do
subject(:put) { described_class.new(client:) }

let(:client) { double("DocumentService::Client", update_document: nil) }
let(:logger) { double("Logger", add: nil) }
let(:redlock_client) { instance_double(Redlock::Client) }
Expand All @@ -25,12 +23,13 @@
double(name: "document-name"),
)

put.call(
described_class.new(
"some_content_id",
{ foo: "bar" },
content: "some content",
payload_version: "1",
)
client:,
).call
end

it "updates the document" do
Expand Down Expand Up @@ -75,12 +74,13 @@
allow(redis_client).to receive(:get)
.with("search_api_v2:latest_synced_version:some_content_id").and_return("42")

put.call(
described_class.new(
"some_content_id",
{ foo: "bar" },
content: "some content",
payload_version: "1",
)
client:,
).call
end

it "does not update the document" do
Expand All @@ -104,12 +104,13 @@
allow(redis_client).to receive(:get)
.with("search_api_v2:latest_synced_version:some_content_id").and_return(nil)

put.call(
described_class.new(
"some_content_id",
{ foo: "bar" },
content: "some content",
payload_version: "1",
)
client:,
).call
end

it "updates the document" do
Expand Down Expand Up @@ -137,12 +138,13 @@
before do
allow(redlock_client).to receive(:lock!).and_raise(error)

put.call(
described_class.new(
"some_content_id",
{ foo: "bar" },
content: "some content",
payload_version: "1",
)
client:,
).call
end

it "updates the document regardless" do
Expand All @@ -167,7 +169,7 @@
before do
allow(client).to receive(:update_document).and_raise(err)

put.call("some_content_id", {}, payload_version: "1")
described_class.new("some_content_id", {}, payload_version: "1", client:).call
end

it "logs the failure" do
Expand Down

0 comments on commit 056c25f

Please sign in to comment.