Skip to end of metadata
Go to start of metadata

Scripts can be scheduled to run at a certain date and time. This is very useful when operating on large data sets, since there is a default limit of 30 seconds for the script execution time. So a script can be coded to handle the data in batches and to reschedule itself at the end of its execution.Scripts can also be scheduled to run at regular time intervals.  

Schedule a Script

A script can be scheduled by saving a document containing the scheduling information.

 In order to schedule a script to run at a certain date, you will need to call the SaveDocument API to save a document with the following special fields:

Fields Name   Description

apsST_scriptName       

The name of the script to be scheduled

apsST_execAt

The date and time at which the script will run

apsST_execAt.apsdb.fieldType 

This should be set to "date" to indicate the type of the apsST_execAt field

apsST_saveResult

A boolean indicating whether to save the result of calling the script in the scheduling document

 

 In order to run a script on regular time intervals . You will need to call the SaveDocument API to save a document with the following special fields:

Fields NameDescription
apsST_scriptNameThe name of the script to be scheduled
apsST_cronSpecThe cron definition that determines at what time intervals the script will run. Refer to the quartz cron tutorial for  information about how to define the cronspec as the same syntax is used by apstrata. Seconds precision has to be defined but is not currently supported.

apsST_saveResult   

A boolean indicating whether to save the result of calling the script in the scheduling document

Handling Triggered Scripts

When the script is triggered, the store and the key of the document triggering the script will be passed as parameters. These parameters can be accessed from within the script as follows:

The running/execution statuses and results of a triggered script can be checked by inspecting the value of the following system fields, which are added to the scheduling document:

Fields NameDescription
apsST_statusIndicates the running status of the script; the possible values of this field are: "queued" to indicate that the script is still pending execution, "fired" to indicate that the script is executing, and  "complete" to indicate that the script has finished executing only in the case of non cron scheduled scripts.
apsST_resultContains the result value returned by the script
apsST_errorContains any error messages resulting from the run of the script
apsST_executionStatusIndicates whether the script completed successfully or failed; the possible values of this field are "success" or "failure" respectively.

Handling Fail-overs

Fail -overs are very rare but possible.

  • If a failover occurred while the scheduled script is getting executed at a specified time, the script will be re-executed as soon as the system recovers and the X-APS-ScriptRecoveryMode request header will be set to true.
    To implement the recovery from the failover, since it is not guaranteed that the script was executed successfully during unexpected system failure, the header must be accessed from within the script as show below:
               request.headers['X-APS-ScriptRecoveryMode']
  • If a failover occurred wile the script is getting executed at regular intervals, the apsST_systemRecovery field will be added to the scheduling document.The system will not rerun the script as it recovers, the script will be executed normally at the next time it's supposed to run.

Cancel a Scheduled Script

A scheduled script can be cancelled by calling SaveDocument and passing an empty value to the apsST_execAt field or the  apsST_scriptName field.

 

 

  • No labels