sgx-jmp

created pr with sgx-jmp/resume-orders.1 on 2026-11-23T18:54:18Z · by 9e834e0d
commented on 2026-11-26T00:39:37Z · by 3c31bc8c
lgtm
cmds
checkout latest patchset:
ssh pr.pico.sh pull sgx-jmp:resume-orders | git am -3
checkout specific patchset revision:
ssh pr.pico.sh pull sgx-jmp:resume-orders [rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh sgx-jmp:resume-orders
add comment to patch request:
ssh pr.pico.sh comment sgx-jmp:resume-orders "lgtm!"

Patchset sgx-jmp/resume-orders.1 on 2026-11-23T18:54:18Z · commit dc9023f

If order takes too long, respond to user
Stephen Paul Weber 2026-11-23T18:53:29Z
So their app doesn't time out
Diff stat
lib/bandwidth_tn_order.rb | 20 +++++++++-----
lib/registration.rb | 16 ++++++++++-
test/test_bandwidth_tn_order.rb | 45 ++++++++++++++++++++++++++++++
test/test_registration.rb | 45 ++++++++++++++++++++++++++++++
test/test_tel_selections.rb | 29 +++++++++++++++++++
7 files changed, 159 insertions(+), 9 deletions(-)
Semantic diff summary
0 added, 0 modified, 0 signature changed, 0 removed across 0 analyzed files (7 files skipped: unsupported file type)
+7 -0 forms/registration/tn_order_wait.rb #
......@@ -0,0 +1,7 @@
1+result!
2+title "Order Processing..."
3+
4+instructions(
5+ "Your order is being processed. " \
6+ "Press next to check if it is ready."
7+)
+13 -7 lib/bandwidth_tn_order.rb #
......@@ -64,7 +64,7 @@ class BandwidthTNOrder
6464 [@order[:error_list]].flatten.first&.dig(:error, :description)
6565 end
6666
67- def poll
67+ def poll(**)
6868 raise "Unknown order status: #{status}"
6969 end
7070
......@@ -82,10 +82,12 @@ class BandwidthTNOrder
8282 def charge(*); end
8383
8484 def order(_, customer)
85- BandwidthTNOrder.get(@order_id).then(&:poll).then { |order|
85+ BandwidthTNOrder.get(@order_id).then(&:poll).then do |order|
86+ next order if order.is_a?(BandwidthTNOrder::Received)
87+
8688 @tel = order.tel
8789 customer
88- }
90+ end
8991 end
9092
9193 def to_s
......@@ -98,9 +100,13 @@ class BandwidthTNOrder
98100 :received
99101 end
100102
101- def poll
103+ def poll(remaining: 15)
104+ return EMPromise.resolve(self) if remaining <= 0
105+
102106 EM.promise_timer(1).then do
103- BandwidthTNOrder.get(id).then(&:poll)
107+ BandwidthTNOrder.get(id).then do |order|
108+ order.poll(remaining: remaining - 1)
109+ end
104110 end
105111 end
106112 end
......@@ -121,7 +127,7 @@ class BandwidthTNOrder
121127 end
122128 end
123129
124- def poll
130+ def poll(**)
125131 EMPromise.resolve(self)
126132 end
127133 end
......@@ -131,7 +137,7 @@ class BandwidthTNOrder
131137 :failed
132138 end
133139
134- def poll
140+ def poll(**)
135141 raise "Order failed: #{id} #{error_description}"
136142 end
137143 end
+15 -1 lib/registration.rb #
......@@ -744,7 +744,7 @@ class Registration
744744 return buy_number if @customer.balance < @tel.price
745745
746746 @tel.order(DB, @customer).then(
747- method(:customer_active_tel_purchased),
747+ method(:order_polled),
748748 method(:number_purchase_error)
749749 )
750750 end
......@@ -759,6 +759,20 @@ class Registration
759759 end
760760 end
761761
762+ def order_polled(result)
763+ return wait_for_order(result) if result.is_a?(BandwidthTNOrder::Received)
764+
765+ customer_active_tel_purchased(result)
766+ end
767+
768+ def wait_for_order(order)
769+ @tel = BandwidthTNOrder::Resume.new(order.id)
770+ Command.reply { |reply|
771+ reply.allowed_actions = [:next]
772+ reply.command << FormTemplate.render("registration/tn_order_wait")
773+ }.then { write }
774+ end
775+
762776 def number_purchase_error(e)
763777 Command.log.error "number_purchase_error", e
764778 BandwidthTnOrderRepo.new.delete(@customer)
+5 -1 lib/tel_selections.rb #
......@@ -334,9 +334,13 @@ class TelSelections
334334 reservation_id: rid
335335 ).then(&:poll)
336336 }.then { |order|
337- repo.set(customer, order.id).then { customer }
337+ repo.set(customer, order.id).then { order_result(order, customer) }
338338 }
339339 end
340+
341+ def order_result(order, customer)
342+ order.is_a?(BandwidthTNOrder::Received) ? order : customer
343+ end
340344 end
341345
342346 class LocalInventory < SimpleDelegator
+45 -0 test/test_bandwidth_tn_order.rb #
......@@ -116,6 +116,24 @@ class BandwidthTNOrderTest < Minitest::Test
116116 end
117117 em :test_order
118118
119+ def test_order_pending
120+ stub_request(
121+ :get,
122+ "https://dashboard.bandwidth.com/v1.0/accounts//orders/oid"
123+ ).to_return(status: 200, body: <<~RESPONSE)
124+ <OrderResponse>
125+ <OrderStatus>RECEIVED</OrderStatus>
126+ </OrderResponse>
127+ RESPONSE
128+ customer = Object.new
129+ resume = BandwidthTNOrder::Resume.new("oid")
130+ result = resume.order(nil, customer).sync
131+ assert_kind_of BandwidthTNOrder::Received, result
132+ assert_equal "oid", result.id
133+ assert_nil resume.tel
134+ end
135+ em :test_order_pending
136+
119137 def test_price
120138 assert_equal 0, BandwidthTNOrder::Resume.new("oid").price
121139 end
......@@ -146,6 +164,33 @@ class BandwidthTNOrderTest < Minitest::Test
146164 assert_requested req
147165 end
148166 em :test_poll
167+
168+ def test_poll_gives_up_and_returns_received
169+ req = stub_request(
170+ :get,
171+ "https://dashboard.bandwidth.com/v1.0/accounts//orders/oid"
172+ ).to_return(status: 200, body: <<~RESPONSE)
173+ <OrderResponse>
174+ <OrderStatus>RECEIVED</OrderStatus>
175+ </OrderResponse>
176+ RESPONSE
177+ result = @order.poll.sync
178+ assert_kind_of BandwidthTNOrder::Received, result
179+ assert_equal "oid", result.id
180+ assert_equal :received, result.status
181+ assert_requested req, times: 15
182+ end
183+ em :test_poll_gives_up_and_returns_received
184+
185+ def test_poll_no_attempts_when_out_of_time
186+ result = @order.poll(remaining: 0).sync
187+ assert_same @order, result
188+ assert_not_requested(
189+ :get,
190+ "https://dashboard.bandwidth.com/v1.0/accounts//orders/oid"
191+ )
192+ end
193+ em :test_poll_no_attempts_when_out_of_time
149194 end
150195
151196 class TestComplete < Minitest::Test
+45 -0 test/test_registration.rb #
......@@ -1539,6 +1539,51 @@ class RegistrationTest < Minitest::Test
15391539 end
15401540 em :test_write
15411541
1542+ def test_write_order_received_waits
1543+ create_order = stub_request(
1544+ :post,
1545+ "https://dashboard.bandwidth.com/v1.0/accounts//orders"
1546+ ).to_return(status: 201, body: <<~RESPONSE)
1547+ <OrderResponse>
1548+ <Order>
1549+ <id>test_order</id>
1550+ </Order>
1551+ </OrderResponse>
1552+ RESPONSE
1553+ get_order = stub_request(
1554+ :get,
1555+ "https://dashboard.bandwidth.com/v1.0/accounts//orders/test_order"
1556+ ).to_return(status: 200, body: <<~RESPONSE)
1557+ <OrderResponse>
1558+ <OrderStatus>RECEIVED</OrderStatus>
1559+ </OrderResponse>
1560+ RESPONSE
1561+ result = execute_command do
1562+ Command::COMMAND_MANAGER.expect(
1563+ :write,
1564+ EMPromise.reject(StandardError.new("stop")),
1565+ [Matching.new do |reply|
1566+ assert_equal [:execute, :next], reply.allowed_actions
1567+ assert_equal :result, reply.form.type
1568+ assert_match(
1569+ /Press next/,
1570+ reply.form.instructions
1571+ )
1572+ end]
1573+ )
1574+ @finish.write.catch { |e| e }
1575+ end
1576+ assert_equal "stop", result.message
1577+ assert_requested create_order
1578+ assert_requested get_order, at_least_times: 1
1579+ assert_kind_of(
1580+ BandwidthTNOrder::Resume,
1581+ @finish.instance_variable_get(:@tel)
1582+ )
1583+ assert_mock Command::COMMAND_MANAGER
1584+ end
1585+ em :test_write_order_received_waits
1586+
15421587 def test_write_with_pending_code
15431588 create_order = stub_request(
15441589 :post,
+29 -0 test/test_tel_selections.rb #
......@@ -276,6 +276,35 @@ class TelSelectionsTest < Minitest::Test
276276 )
277277 end
278278 em :test_order_stores_order_id
279+
280+ def test_order_returns_received_order
281+ stub_request(
282+ :post,
283+ "https://dashboard.bandwidth.com/v1.0/accounts//orders"
284+ ).to_return(status: 200, body: <<~RESPONSE)
285+ <OrderResponse>
286+ <Order>
287+ <id>order-id</id>
288+ </Order>
289+ </OrderResponse>
290+ RESPONSE
291+ stub_request(
292+ :get,
293+ "https://dashboard.bandwidth.com/v1.0/accounts//orders/order-id"
294+ ).to_return(status: 200, body: <<~RESPONSE)
295+ <OrderResponse>
296+ <OrderStatus>RECEIVED</OrderStatus>
297+ </OrderResponse>
298+ RESPONSE
299+ result = @tn.order(FakeDB.new, @customer).sync
300+ assert_kind_of BandwidthTNOrder::Received, result
301+ assert_equal "order-id", result.id
302+ assert_kind_of(
303+ BandwidthTNOrder::Resume,
304+ BandwidthTnOrderRepo.new.get(@customer).sync
305+ )
306+ end
307+ em :test_order_returns_received_order
279308 end
280309
281310 class TnOptionTest < Minitest::Test
Back to top