Regular execution

Switch expects one or both of the following two entry points to be present in each script:

jobArrived( s : Switch, job : Job )

This entry point is invoked each time a new job arrives in one of the input folders for the script element. The newly arrived job is passed to the entry point as the second argument.

//logs the name of each incoming job
function jobArrived( s : Switch, job : Job ) 
{
    job.log(1, job.getName());
} 
timerFired( s : Switch )

This entry point is invoked for the first time immediately after the flow is activated and thereafter it is invoked at regular intervals regardless of whether a new job arrived or not. The default value for the interval is 300 seconds (5 minutes); it can be modified with Switch.setTimerInterval().

//logs the username each 10+,20+,10+,20+,... seconds 
function timerFired( s : Switch ) {
    if(s.getTimerInterval() == 10){
        s.setTimerInterval(20);  
    }  
    else{
        s.setTimerInterval(10);  
    }  
    s.log(1, s.getSystemInfo("UserName"));
}