We have some processes that run from an ExtJS ui that imports and
syncs records from external sources.

It runs a script to increase the timeout because some of the scripts
could take a while.  Then it runs the script itself in a process from
within 4D called via direct execution.

I've outlined the process below if anyone is interested.

It works well, but we have recently, by accident, come across one of
the scripts that does not execute and gives an A4D "resource could not
be found error".  The only way we got it to work was to _shorten_ the
file name, thus making me think that there is a limit on the file path
variable length from within A4D.  This is odd because 4D sees the file
using Test Path Name (top of method A4DSPExecuteFile).  It is when
Calling the file for direct execution that A4D has an error (bottom of
method A4DSPExecuteFile at the $status variable assignment).

Is A4D Native to URL path (Document)  evaluate only a string when it
should be text?

Thanks,

Michael Check


###############
In 4D:

  ` Method: SP_A4DSPProcessLaunch
  ` Description
  `
  `
  ` Parameters
  ` ----------------------------------------------------


C_TIME($docRef)

C_TEXT($1;Document)
Document:=$1

C_LONGINT($stackSize;$pid)
$stackSize:=2048*80
C_TEXT($pName)
$pName:=UTL_FilePath2FileName (Document)
$pid:=New process("SP_A4DSPExecuteFile";$stackSize;$pName;Document)

  ` End of method

################

  ` Method: SP_A4DSPExecuteFile
  ` Description
  ` Called from SP_A4DSPProcessLaunch
  ` This will grab an A4D script and execute it in a server process
  ` Make sure that location of script to be run in in the Active4D ini
safe_dir directives, otherwise it will get HTTP403 (forbidden)
  `
  ` Parameters
  ` SP_A4DSPExecuteFile ($filePath:T )
  ` $1: Full Path of File to Execute
  ` ----------------------------------------------------

C_TEXT($1)
C_TEXT(Document)
Document:=$1

C_BOOLEAN($fileExists)
$fileExists:=(Test path name(Document)=1)


If ($fileExists)
        A4D_RemoteAddr:=◊A4D_HostAddr
        
        MESSAGES OFF
        READ ONLY(*)
        
        C_LONGINT(A4D_Error)
        A4D_Error:=0
        ON ERR CALL("A4D_ErrorHandler")
        
        C_BLOB($response)
        C_LONGINT($status;$ticks)
        SET BLOB SIZE($response;0)
        $status:=HTTP Status OK
        ARRAY TEXT($responseHeaderNames;0)
        ARRAY TEXT($responseHeaderValues;0)
        
        ARRAY TEXT($requestInfo;4)
        $requestInfo{A4D Request Remote Addr }:=A4D_RemoteAddr
        $requestInfo{A4D Request Host Addr }:=◊A4D_HostAddr
        $requestInfo{A4D Request Host Port }:="0"
        $requestInfo{A4D Request Secure }:="0"
        
        $ticks:=Tickcount
        $status:=A4D Execute file (A4D Native to URL path
(Document);A4D_QueryParams;$requestInfo;$responseHeaderNames;$responseHeaderValues;$response)
        $ticks:=Tickcount-$ticks
        
        ON ERR CALL("")
        ` A4D_ShowOutput ($response;$status;$ticks)
        
        ARRAY TEXT($responseHeaderNames;0)
        ARRAY TEXT($responseHeaderValues;0)
        SET BLOB SIZE($response;0)
End if

#################
In A4D:

Default Directory/stored_procedures/set_timeout_long.a4d

<%
        
        set script timeout(2000)
        
%>


#################

Default Directory/stored_procedures/populate_overnights.a4d

<%
// reset the script timeout right away for the next run of A4D
set script timeout(30)

// Do all your long operation stuff that will be run inside it's own process.
//
// LONG OPERATION HERE...
//
//

%>


#################

Default 
Directory/sites/script_that_is_executed_to_launch_A4D_Direct_Execution.a4d

(we do this with ExtJS using and Ajax call, this is the file called with ajax)

<%
method "overnights"

        $path := join paths(*; default directory; "stored_procedures")

        $file := "set_timeout_long.a4d"
        $filepath := join paths(*; $path; $file)
        $cmd := 'SP_A4DSPProcessLaunch("%s")' % ($filepath)
        execute in 4d(a4d.utils.chopText($cmd))
        
        $file := "populate_overnights.a4d"
        $filepath := join paths(*; $path; $file)
        $cmd := 'SP_A4DSPProcessLaunch("%s")' % ($filepath)
        execute in 4d(a4d.utils.chopText($cmd))
                        
        $json:= a4d.json.new
        $json->add("success";true)
        $json->add("msg";"Overnight Addresses have been updated successfully.")
        $json->write

end method


// handle the incoming task
if(form variables has("task"))
        $task:=_form{"task"}
        case of

                :($task="programs")
                        programs

                :($task="overnights")
                        overnights
        else
                write('{success:false,msg:"Task Not Found: ajax_dataMgmt.a4d"}')
        end case
end if
%>
_______________________________________________
Active4D-dev mailing list
[email protected]
http://mailman.aparajitaworld.com/mailman/listinfo/active4d-dev
Archives: http://mailman.aparajitaworld.com/archive/active4d-dev/

Reply via email to