admin管理员组

文章数量:1126324

Something very strange is happening to me.

From my controller I do:

CreateMassBalanceJob.set(wait: 1.seconds).perform_later(
      excel_file_path: path_to_tmp_file,
      mass_balance_id: @mass_balance.id

CreateMassBalanceJob runs this method:

def stream_notification_message(message, type: 'success')
    notification_stream = notification_message_helper_stream(message,
                                                             to_string: true,
                                                             type:)

    puts 'ENTRA EN stream_notification_message'
    Turbo::StreamsChannel.broadcast_prepend_to(
      'global_notifications',
      target: 'notifications_',
      html: notification_stream
    )

    puts 'SALE EN stream_notification_message'
  end

In it I write the Input and Output for issues of debug what is happening.

I do a Turbo::StreamsChannel.broadcast_prepend_to through the global_notifications channel to send a notification to the user's view.

But sometimes it happens that, even though the debug output clearly shows me that the method is executed only once, and that broadcast_prepend_to is executed only once, the Backend sends the action 3 times (sometimes more. It's random).

It is also observed in the Web browser on the client side:

In the application.html.erb layout I have:

<%= turbo_stream_from :global_notifications %>

And obviously, it is showing me the same notification message several times:

I don't know what else to check. Has this happened to anyone else?

I am using:

  • OS: Windows 11
  • ruby 3.2.6
  • Rails 8.0.1

本文标签: ruby on railsTurboStreamsChannel sends the same action multiple timesStack Overflow