Rende sticky e capacizzati i relay YouTube su coda dedicata.
Evita doppi ffmpeg tra host: stop solo sull'owner, ensure con requeue a capacità piena e coda Sidekiq youtube_relay isolata. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -21,4 +21,46 @@ RSpec.describe Streams::YoutubeRelay do
|
||||
expect(cmd).not_to include("-b:a")
|
||||
end
|
||||
end
|
||||
|
||||
describe "multi-host sticky stop/capacity" do
|
||||
let(:redis) { Redis.new(url: ENV.fetch("REDIS_URL", "redis://redis:6379/0")) }
|
||||
let(:session_id) { SecureRandom.uuid }
|
||||
|
||||
before do
|
||||
allow(described_class).to receive(:worker?).and_return(true)
|
||||
allow(described_class).to receive(:worker_id).and_return("worker-a")
|
||||
allow(described_class).to receive(:max_concurrent).and_return(1)
|
||||
redis.flushdb
|
||||
end
|
||||
|
||||
def session_double
|
||||
instance_double(
|
||||
StreamSession,
|
||||
id: session_id,
|
||||
platform: "youtube",
|
||||
terminal?: false,
|
||||
stream_key: "yt-key",
|
||||
status: "live"
|
||||
)
|
||||
end
|
||||
|
||||
it "does not stop ffmpeg owned by another worker" do
|
||||
redis.set(format(Streams::YoutubeRelay::OWNER_KEY, session_id), "worker-b", ex: 3600)
|
||||
redis.set(format(Streams::YoutubeRelay::REDIS_KEY, session_id), "12345", ex: 3600)
|
||||
|
||||
expect(described_class.stop_on_worker!(session_double)).to eq(:wrong_host)
|
||||
expect(redis.get(format(Streams::YoutubeRelay::OWNER_KEY, session_id))).to eq("worker-b")
|
||||
end
|
||||
|
||||
it "requeues ensure when at capacity" do
|
||||
other_id = SecureRandom.uuid
|
||||
redis.sadd(format(Streams::YoutubeRelay::OWNED_SET, "worker-a"), other_id)
|
||||
allow(described_class).to receive(:intake_available?).and_return(true)
|
||||
expect(YoutubeRelayEnsureJob).to receive(:set).with(hash_including(wait: 5.seconds, queue: :youtube_relay)).and_return(
|
||||
double(perform_later: true)
|
||||
)
|
||||
|
||||
expect(described_class.ensure_on_worker!(session_double)).to eq(:at_capacity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user