Broadcast job progress updates to a Turbo Frame

6414
0

Long-running jobs are where Hotwire can feel magical: start an export, then watch progress update live. I give each job a “progress” model, render it in a turbo_frame_tag, and broadcast replacements as the job advances. The job updates percent and status, then uses Turbo::StreamsChannel.broadcast_replace_to to replace the frame content. The UI stays server-rendered, so you don’t need a websocket protocol for progress—just send rendered HTML fragments. This is also easy to secure because the stream can be scoped to [current_member, export]. I keep the broadcast payload small and avoid calling expensive methods inside the partial since it may render many times during a single job.