Class ::nsmcp::QuestionJobPoller (public)
::nx::Class ::nsmcp::QuestionJobPoller
Defined in /usr/local/ns/tcl/nsmcp/question-backend.tcl
- Testcases:
- No testcase defined.
Source code: :public object method wait {name json deadline emit poll {check {}}} { # # Wait for a background tool job while reporting its progress. # # Allow at most one second for queued or running jobs to finish. # Emit status and honor cancellation without restarting the original job. # # @param name Name of the configured or registered item to resolve. # @param json Serialized JSON supplied by the backend transport. # @param deadline Absolute deadline in clock milliseconds. # @param emit Event callback prefix; returning false requests cancellation. # @param poll Callback prefix invoked with a retained background-job handle. # @param check Optional callback used to check cancellation or other turn # constraints. # # @return Final evidence or the latest retained-job JSON when still pending; # ordinary non-job results pass through unchanged. # set delay 0.1 set waitUntil [expr {min($deadline,[clock milliseconds]+1000)}] while {1} { set value [ns_json parse $json] if {[dict exists $value isError] && [dict get $value isError]} { return $json } if {![dict exists $value structuredContent jobHandle]} { return $json } set job [dict get $value structuredContent] set handle [dict get $job jobHandle] if {![regexp {^[0-9a-f]{64}$} $handle] || ![dict exists $job status]} { return $json } set status [dict get $job status] set event [dict create type job name $name jobHandle $handle status $status] foreach key {progress processingTime queueOccupancy} { if {[dict exists $job $key]} {dict set event $key [dict get $job $key]} } if {![uplevel #0 [list {*}$emit $event]]} { return -code error -errorcode {NSMCP QUESTION CANCELLED} "Question cancelled; background jobHandle: $handle" } if {$status ni {queued running}} { return $json } if {[clock milliseconds] >= $deadline} { error "Question timed out waiting for background jobHandle $handle; use log_results with this handle to continue" } # Fast jobs often finish just after their queued descriptor returns. # Give both queued and running work the same bounded grace period. if {[clock milliseconds] >= $waitUntil} { return $json } if {$check ne ""} { uplevel #0 $check } ns_sleep [expr {min($delay,max(0.001,($waitUntil-[clock milliseconds])/1000.0))}] set json [uplevel #0 [list {*}$poll $handle]] set delay [expr {min(1.0,$delay*1.5)}] } }XQL Not present: Generic, PostgreSQL, Oracle
![[i]](/resources/acs-subsite/ZoomIn16.gif)