How do I configure Turbo::Streams::*Job for a different, non-default queue?

How do I configure Turbo::Streams::*Job classes to use a different, non-default queue?

When a broadcast job is created via broadcast_replace_later_to, a Turbo::Streams::ActionBroadcastJob job is created:

Enqueued Turbo::Streams::ActionBroadcastJob (Job ID: <uuid>)
to Sidekiq(<config.active_job.queue_name_prefix>_<config.active_job.default_queue_name>) with arguments: <...>

Naturally, one would want to have broadcast notifications to be as close to realtime as possible. And “default” queue is not the best place for that, because it processes all kinds of jobs, including ones that can take minutes to complete. Instead of messing with the default queue, I’d prefer to have turbo’s jobs be processed in a high-prio queue; say, “realtime”.

Unfortunately, at the moment, Turbo does not allow this kind of customisation. So the next idea that comes to mind is "okay, let’s patch the Turbo::Streams::ActionBroadcastJob class and add queue_as :realtime, that shouldn’t be hard… Alas, that didn’t work: broadcast jobs are still being enqueued in an <env>_default queue. I’ve tried copying over the whole class, placed it in app/jobs/turbo/streams/action_broadcast_job.rb, with the “queue_as” line added - still no luck.

So, my question is:

  • is there any other way, if any at all, how to configure the queue, into which Turbo::Streams::ActionBroadcastJob jobs are enqueued?
  • what am I doing wrong with patching here?
  • how do I get it to do what I want?..

You can create an initializer, e.g., config/initializers/turbo_streams.rb and configure your queue names for each Turbo::Streams::*Job you wish to move to a different queue:

Turbo::Streams::BroadcastJob.queue_name = "turbo_streams_#{Rails.env}"
Turbo::Streams::ActionBroadcastJob.queue_name = "turbo_streams_#{Rails.env}"
Turbo::Streams::BroadcastStreamJob.queue_name = "turbo_streams_#{Rails.env}"
1 Like