Broadcast a status badge update on background processing

8382
0

A lot of Rails apps have records that transition through states: queued, processing, done. With Hotwire, I render a status badge partial and broadcast replacements when the state changes. A background job updates the record, and the model broadcasts a replace to the stream. On the page, I wrap the badge in a turbo_frame_tag dom_id(record, :status) so it can be swapped cleanly. The benefit is instant feedback without polling. The key is broadcasting a partial that’s cheap to render and doesn’t accidentally load a bunch of associations. If the job can fail, I also broadcast an error badge with a retry link.