How is the Switch way to create a script with timeout (like Assemble job)?

Post Reply
alanoliveira
Newbie
Posts: 17
Joined: Mon Sep 15, 2014 10:48 pm

How is the Switch way to create a script with timeout (like Assemble job)?

Post by alanoliveira »

Hello guys
I need to send a pdf to a hotfolder of an external application hotfolder and read the output folder waiting the result, if the result is not there in x minutes I'll proceed with original file.
But I don't know how.

I first thought in use the jobArrived to set a variable with current time, copy the input file to my external application hotfolder and use a kind of looping to verify if the output folder has the file or the time is exceeded, but this is not a good idea because I'll lock a process.
So I though in use the timerFired, but I don't know how can I get the time which job is waiting, and each time that timerFired is executed it will copy the input file to the hotfolder.

Any of you have a ideia how can I do it?

Kind regards
cstevens
Member
Posts: 40
Joined: Tue Feb 12, 2013 8:42 pm

Re: How is the Switch way to create a script with timeout (like Assemble job)?

Post by cstevens »

This is how I did it recently in one of my scripts (This is checking incoming jobs to a script on a timer interval, but you could easily change it to look at another directory and check the age of the files in that directory). I also had a property value named "timeout" where I set the timeout for files in seconds.

Code: Select all

var currentTime = Number(new Date());
var fileModifiedTime = Number(new File(jobsList.at(i).getPath()).lastModified);
var fileAge = (currentTime - fileModifiedTime)/1000;
if (s.getPropertyValue("timeout") < fileAge){
 //continue on with existing PDF file
}
else {
  //check remote directory for file's existence..
}
freddyp
Advanced member
Posts: 413
Joined: Thu Feb 09, 2012 3:53 pm

Re: How is the Switch way to create a script with timeout (like Assemble job)?

Post by freddyp »

Your first idea is basically correct, but the implementation is a bit different.

The "variable" you set in jobArrived is called private data (job.setPrivateData, job.getPrivateData). This is a property of the job and sticks to it even when exiting the script. You can exit jobArrived without doing a sendTo; the job will stay in the input folder. Copying the job to the input folder of the external application is done with s.copy.

timerFired is in fact the loop you describe: Switch calls timerFired with a certain interval (s.setTimerInterval), so you do not have to loop over a period of time. You do have to loop over all the waiting jobs (s.getJobs). For every job you check if there is a matching job in the output folder. If there is, you send that file to the outgoing connection. If not and the current time is as far ahead of the value you stored in private data as the time you want to wait (warning: private data only stores strings!), you send on the original file (job.getPath()).

Warning about the method you use when sending the job: it is best to use variableForWaitingJobsList.at(loopVariable).sendTo... and not to create a new job so you keep the metadata and properties!
Post Reply