Class: Upkeep::Delivery::TurboStreams

Inherits:
Object
  • Object
show all
Defined in:
lib/upkeep/delivery/turbo_streams.rb

Defined Under Namespace

Classes: Batch, Envelope, Stream

Constant Summary collapse

DELIVERY_ERROR =
"delivery_error.upkeep"

Instance Method Summary collapse

Instance Method Details

#build(plan) ⇒ Object



144
145
146
# File 'lib/upkeep/delivery/turbo_streams.rb', line 144

def build(plan)
  build_many([plan])
end

#build_many(plans) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/upkeep/delivery/turbo_streams.rb', line 148

def build_many(plans)
  payload = {
    plans: plans.size,
    planned_targets: plans.sum { |plan| plan.targets.size }
  }

  ActiveSupport::Notifications.instrument("build_turbo_streams.upkeep", payload) do
    streams = plans.flat_map { |plan| stream_targets(plan.targets, request_id: plan.request_id) }.compact
    batch = Batch.new(merge_streams(streams))
    payload.merge!(payload_for(batch, rendered_streams: streams))
    batch
  end
end