[Nitro] de-bouncing Submit Order button

Bill Kelly billk at cts.com
Wed Oct 10 18:32:21 EDT 2007


From: George Moschovitis 
>
> I am not sure I understand your polling idea :(

The polling idea was a method of presenting an, 
"We are processing your order, this may take a moment..."
page, while the server is completing the purchase in an
asynchronous thread.  (Also it was conceived as a way of
eliminating special cases, in that every (possible)
multiple click of the Submit button goes through the same
logic.)

The processing_order page polls "itself" with a 

  <meta http-equiv="refresh" content="3" />
 
and as long as the server is still busy processing the
order, the page remains at the "...this may take a moment."
page.  But when it polls and the order is complete, then
its Controller redirects to a final order complete, or
purchase failed page.

The logic for the refresh page looks like this:

  # This is a meta-refresh holding page... the user can click the Submit button on
  # final_review as much as they like, and they'll end up here
  def processing_order
    do_process_order = false
    $order_sync_mutex.synchronize {
      if session[:order_process_state].nil?
        session[:order_process_state] = :in_process
        do_process_order = true
      end
    }

    if do_process_order
      kickoff_async_process_order_and_bill_cc
      sleep 2.0  # if it hasn't completed by this time, we'll show the "This may take a moment..." page
    end

    order_state = $order_sync_mutex.synchronize { session[:order_process_state] }
    case order_state
    when :complete then redirect :order_complete
    when :fail     then redirect :purchase_error
    else                # continue and display the processing_order meta refresh html
    end
  end

So, everytime processing_order is invoked, it checks the
session[:order_process_state] value.  If we haven't begun
processing the order yet, it knows to kick off the async
processing.  Regardless, it always checks the current
session[:order_process_state] at the end, to determine
whether to remain on the "This may take a moment" polling
page, or proceed to the purchase succeeded/failed pages.


Does that make sense and/or seem reasonable?


Regards,

Bill




More information about the Nitro-general mailing list