sgx-jmp
created pr with
sgx-jmp/resume-orders.1
commented
lgtm
cmds
checkout latest patchset:
ssh pr.pico.sh pull sgx-jmp:resume-orders | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull sgx-jmp:resume-orders [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh sgx-jmp:resume-ordersadd comment to patch request:
ssh pr.pico.sh comment sgx-jmp:resume-orders "lgtm!"
Patchset
sgx-jmp/resume-orders.1
If order takes too long, respond to user
Stephen Paul Weber
2026-11-23T18:53:29ZSo their app doesn't time out
Diff stat
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
#
+13
-7
lib/bandwidth_tn_order.rb
#
| ... | ... | @@ -82,10 +82,12 @@ class BandwidthTNOrder | |
| 82 | 82 | def charge(*); end | |
| 83 | 83 | ||
| 84 | 84 | 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 | + | ||
| 86 | 88 | @tel = order.tel | |
| 87 | 89 | customer | |
| 88 | - | } | |
| 90 | + | end | |
| 89 | 91 | end | |
| 90 | 92 | ||
| 91 | 93 | def to_s |
| ... | ... | @@ -98,9 +100,13 @@ class BandwidthTNOrder | |
| 98 | 100 | :received | |
| 99 | 101 | end | |
| 100 | 102 | ||
| 101 | - | def poll | |
| 103 | + | def poll(remaining: 15) | |
| 104 | + | return EMPromise.resolve(self) if remaining <= 0 | |
| 105 | + | ||
| 102 | 106 | 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 | |
| 104 | 110 | end | |
| 105 | 111 | end | |
| 106 | 112 | end |
+15
-1
lib/registration.rb
#
| ... | ... | @@ -759,6 +759,20 @@ class Registration | |
| 759 | 759 | end | |
| 760 | 760 | end | |
| 761 | 761 | ||
| 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 | + | ||
| 762 | 776 | def number_purchase_error(e) | |
| 763 | 777 | Command.log.error "number_purchase_error", e | |
| 764 | 778 | BandwidthTnOrderRepo.new.delete(@customer) |
+5
-1
lib/tel_selections.rb
#
| ... | ... | @@ -334,9 +334,13 @@ class TelSelections | |
| 334 | 334 | reservation_id: rid | |
| 335 | 335 | ).then(&:poll) | |
| 336 | 336 | }.then { |order| | |
| 337 | - | repo.set(customer, order.id).then { customer } | |
| 337 | + | repo.set(customer, order.id).then { order_result(order, customer) } | |
| 338 | 338 | } | |
| 339 | 339 | end | |
| 340 | + | ||
| 341 | + | def order_result(order, customer) | |
| 342 | + | order.is_a?(BandwidthTNOrder::Received) ? order : customer | |
| 343 | + | end | |
| 340 | 344 | end | |
| 341 | 345 | ||
| 342 | 346 | class LocalInventory < SimpleDelegator |
+45
-0
test/test_bandwidth_tn_order.rb
#
| ... | ... | @@ -116,6 +116,24 @@ class BandwidthTNOrderTest < Minitest::Test | |
| 116 | 116 | end | |
| 117 | 117 | em :test_order | |
| 118 | 118 | ||
| 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 | + | ||
| 119 | 137 | def test_price | |
| 120 | 138 | assert_equal 0, BandwidthTNOrder::Resume.new("oid").price | |
| 121 | 139 | end |
| ... | ... | @@ -146,6 +164,33 @@ class BandwidthTNOrderTest < Minitest::Test | |
| 146 | 164 | assert_requested req | |
| 147 | 165 | end | |
| 148 | 166 | 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 | |
| 149 | 194 | end | |
| 150 | 195 | ||
| 151 | 196 | class TestComplete < Minitest::Test |
+45
-0
test/test_registration.rb
#
| ... | ... | @@ -1539,6 +1539,51 @@ class RegistrationTest < Minitest::Test | |
| 1539 | 1539 | end | |
| 1540 | 1540 | em :test_write | |
| 1541 | 1541 | ||
| 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 | + | ||
| 1542 | 1587 | def test_write_with_pending_code | |
| 1543 | 1588 | create_order = stub_request( | |
| 1544 | 1589 | :post, |
+29
-0
test/test_tel_selections.rb
#
| ... | ... | @@ -276,6 +276,35 @@ class TelSelectionsTest < Minitest::Test | |
| 276 | 276 | ) | |
| 277 | 277 | end | |
| 278 | 278 | 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 | |
| 279 | 308 | end | |
| 280 | 309 | ||
| 281 | 310 | class TnOptionTest < Minitest::Test |