- examples/big-suite: E-Commerce 10 functions, 6 layers, real depends_on - provider: nodejs packages now wrapped in ESM zip (buildJSDeployZip) - provider: loadPackageLiteral reads raw file, nodejs zip via source_dir - all 10 functions verified working: python/node/ruby/go runtimes
41 lines
1.1 KiB
Ruby
41 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
require "json"
|
|
|
|
CHANNELS = %w[email sms push].freeze
|
|
|
|
def handler
|
|
# В реальности: читаем body запроса, определяем канал и шлём уведомление
|
|
# Здесь: симуляция отправки по всем каналам
|
|
|
|
order_id = "ORD-DEMO"
|
|
user_name = "Alice"
|
|
amount = 129.99
|
|
|
|
results = CHANNELS.map do |ch|
|
|
# Симуляция: email — всегда ок, sms — 95%, push — 90%
|
|
success = case ch
|
|
when "email" then true
|
|
when "sms" then rand(100) < 95
|
|
when "push" then rand(100) < 90
|
|
end
|
|
{
|
|
channel: ch,
|
|
status: success ? "sent" : "failed",
|
|
message: "Order #{order_id} confirmed — total $#{amount}",
|
|
recipient: "#{user_name.downcase}@notify",
|
|
}
|
|
end
|
|
|
|
sent = results.count { |r| r[:status] == "sent" }
|
|
total = results.length
|
|
|
|
{
|
|
status: "ok",
|
|
order_id: order_id,
|
|
sent: sent,
|
|
failed: total - sent,
|
|
channels: results,
|
|
sent_at: Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
|
|
}.to_json
|
|
end
|