Skip to content

Commit d9cf730

Browse files
authored
Allow running TrimJob out of band when autotrim is disabled (#62)
1 parent f383a58 commit d9cf730

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.3.5
1+
3.4.3

app/jobs/solid_cable/trim_job.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def trim_batch_size
2020
def trim?
2121
expires_per_write = (1 / trim_batch_size.to_f) * ::SolidCable.trim_chance
2222

23-
rand < (expires_per_write - expires_per_write.floor)
23+
!::SolidCable.autotrim? ||
24+
rand < (expires_per_write - expires_per_write.floor)
2425
end
2526
end
2627
end

test/jobs/trim_job_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,19 @@ class TrimJobTest < ActiveJob::TestCase
2020
end
2121
end
2222
end
23+
24+
test "trims when out of band with autotrim disabled" do
25+
SolidCable.stub(:trim_chance, 0) do
26+
with_cable_config autotrim: false, trim_batch_size: 2, message_rention: "1.second" do
27+
4.times do
28+
SolidCable::Message.broadcast("foo", "bar")
29+
SolidCable::Message.update_all(created_at: 2.days.ago)
30+
end
31+
32+
assert_difference -> { SolidCable::Message.count }, -2 do
33+
SolidCable::TrimJob.perform_now
34+
end
35+
end
36+
end
37+
end
2338
end

0 commit comments

Comments
 (0)