ad_return_if_another_copy_is_running (public)

 ad_return_if_another_copy_is_running [ max_simultaneous_copies ] \
    [ call_adp_break_p ]

Defined in packages/acs-tcl/tcl/defs-procs.tcl

Returns a page to the user about how this server is busy if another copy of the same script is running. Then terminates execution of the thread. Useful for expensive pages that do sequential searches through database tables, etc. You don't want to tie up all of your database handles and deny service to everyone else. The call_adp_break_p argument is essential if you are calling this from an ADP page and want to avoid the performance hit of continuing to parse and run.

Parameters:
max_simultaneous_copies (defaults to "1")
call_adp_break_p (defaults to "0")

Partial Call Graph (max 5 caller/called nodes):
%3 ad_conn ad_conn (public) ad_return_warning ad_return_warning (public) ad_return_if_another_copy_is_running ad_return_if_another_copy_is_running ad_return_if_another_copy_is_running->ad_conn ad_return_if_another_copy_is_running->ad_return_warning

Testcases:
No testcase defined.
Source code:
    # Note: on AOLServer, ns_server was seemingly dangerous. This
    # should not affect NaviServer though, see
    # http://openacs.org/forums/message-view?message_id=203381

    # first let's figure out how many are running and queued
    set this_connection_url [ad_conn url]
    set n_matches 0
    foreach connection [ns_server active] {
        set query_connection_url [lindex $connection 4]
        if { $query_connection_url == $this_connection_url } {
            # we got a match (we'll always get at least one
            # since we should match ourselves)
            incr n_matches
        }
    }
    if { $n_matches > $max_simultaneous_copies } {
        ad_return_warning "Too many copies"  "This is an expensive page for our server, which is already running the same program on behalf of some other users.  Please try again at a less busy hour."
        # blow out of the caller as well
        if {$call_adp_break_p} {
            # we were called from an ADP page; we have to abort processing
            ns_adp_break
        }
        return -code return
    }
    # we're okay
    return 1
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: