Skip to content

Commit

Permalink
Pass a String to ActiveJob (rather than a SafeBuffer)
Browse files Browse the repository at this point in the history
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 [hotwired#522] and [hotwired#535]

[1]: https://github.com/sidekiq/sidekiq/wiki/Best-Practices#1-make-your-job-parameters-small-and-simple
[2]: hotwired#535 (comment)
[@jdelStrother]: https://github.com/jdelStrother
[hotwired#522]: hotwired#522
[hotwired#535]: hotwired#535
  • Loading branch information
michaelbaudino authored Apr 26, 2024
1 parent 102a491 commit 4dd0f11
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/jobs/turbo/streams/broadcast_stream_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4dd0f11

Please sign in to comment.