From 4dd0f1167aed58d980d840f842a7267fc3060341 Mon Sep 17 00:00:00 2001 From: Michael Baudino Date: Fri, 26 Apr 2024 11:14:10 +0200 Subject: [PATCH] Pass a String to ActiveJob (rather than a SafeBuffer) This provides compatibility with Sidekiq as an ActiveJob adapter (because [Sidekiq only allows native JSON types][1] to be passed as job arguments). All credit goes to [@jdelStrother] who [suggested this solution][2]. Fixes [#522] and [#535] [1]: https://github.com/sidekiq/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple [2]: https://github.com/hotwired/turbo-rails/issues/535#issuecomment-1946805651 [@jdelStrother]: https://github.com/jdelStrother [#522]: https://github.com/hotwired/turbo-rails/issues/522 [#535]: https://github.com/hotwired/turbo-rails/issues/535 --- app/jobs/turbo/streams/broadcast_stream_job.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/jobs/turbo/streams/broadcast_stream_job.rb b/app/jobs/turbo/streams/broadcast_stream_job.rb index 64cd8378..6d93eea2 100644 --- a/app/jobs/turbo/streams/broadcast_stream_job.rb +++ b/app/jobs/turbo/streams/broadcast_stream_job.rb @@ -4,4 +4,8 @@ class Turbo::Streams::BroadcastStreamJob < ActiveJob::Base def perform(stream, content:) Turbo::StreamsChannel.broadcast_stream_to(stream, content: content) end + + def self.perform_later(stream, content:) + super(stream, content: content.to_str) + end end