Running a macro more than once simultaneously

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
FocusWiz
Posts: 1
Joined: Mon Oct 20, 2014 2:29 am

Running a macro more than once simultaneously

Post by FocusWiz » Mon Oct 20, 2014 4:26 am

I am using VERSION BUILD=88204131 of iMacros for Firefox with Firefox version 33. This is running under Windows 8.1 Professional, 64 bit with 8GB of RAM installed. I have seen discussions of running multiple macros simultaneously, but it was not clear whether they were discussing this particular concern, where I am trying to run the same exact macro simultaneously without interfering with its twin macros.

I am not encountering an error, but this is my first foray into using your product and I am not sure if the techniques I've gleaned from your examples and forums are the best way of accomplishing what I am trying to do. In its simplest sense, I am trying to create a file and upload it to a website. To complicate this, the file could be created multiple times at very uneven intervals. I run up to a dozen instances of Excel (across multiple machines) which are processing information and which each could create a file to be uploaded which will somehow get into a "starting" directory on the machine with iMacros. Excluding the Excel portion that creates the file, I have split this function into three processes.

Process A: A batch file, looks in a "starting" directory and determines if a file has been created. If one exists, it looks to see if there is room in an "upload" directory to copy it to. If so, it will invoke Process B. If no file is there to start or the upload directory already has a file in it, it waits a while and then checks again.

Process B: Another batch file, does some logging of the file it will be processing and then MOVEs it to the "upload" directory for processing by iMacros in Process C. It then invokes Process C with a command like the following:

Code: Select all

MOVE W:\Starting\AWUpload.dat W:\Uploads\AWUpload.txt
ECHO UPLOADING AW FILE
start "" /W /B "C:\Program Files (X86)\Mozilla Firefox\firefox.exe" imacros://run/?m=AWUpload.iim
REM start "" /W /B "C:\Program Files\Mozilla Firefox\firefox.exe" imacros://run/?m=AWUpload.iim
TIMEOUT 15
Process C: The iMacros script, will open a tab using TAB=1, then go to a website and interact with it to upload the file, then delete the file from the "upload" directory with a FILEDELETE and then close the tab it opened with TAB CLOSE.

Since this upload process can take close to half a minute when the website is busy, I want to enable the entire process to support multiple uploads being at least started before the first one has completed. I considered having multiple directories for the files but it seemed that would still need multiple iMacros scripts so that they would know which directory they were working with, so it seems just as simple to just use multiple filenames in the upload directory. I considered having multiple Process A scripts running simultaneously, but I was concerned that I could have these collide with two Process Bs attempting to move the same file from the "starting" directory unless I created some kind of logic to tell each script when a process is already running. Ultimately, I decided it was simplest to have Process A run 3 times (about 10 seconds apart) before looping around to start again, while using triplets of Process B and Process C similar to the following:

Code: Select all

:STARTOVER
timeout 9
IF EXIST "W:\Starting\AWUpload.dat" IF NOT EXIST "W:\Uploads\AWUpload1.txt" CALL AWUpload1.bat
ECHO will check again in 9 seconds...
timeout 9
IF EXIST "W:\Starting\AWUpload.dat" IF NOT EXIST "W:\Uploads\AWUpload2.txt" CALL AWUpload2.bat
ECHO will check again in 9 seconds...
timeout 9
IF EXIST "W:\Starting\AWUpload.dat" IF NOT EXIST "W:\Uploads\AWUpload3.txt" CALL AWUpload3.bat
GOTO STARTOVER
Since I am using a "CALL" I am expecting that each of the Process 2 scripts will move the file out of the starting directory before returning control to the Process A batch file. Each of the AWUploadX batch files is identical except it creates a different file name and calls a different iim specific to process the file name that it is creating with the MOVE command.

This seems to work. At the current speed at which files might be created, it seems sufficient to handle them all and in testing has not attempted to upload the same file more than once (though that is also a concern since the MOVE command may fail if the file has not yet been deleted by the iim from the prior process a half minute ago and I do not think that will stop the batch file from calling another iim file).

So, my questions are:
  1. Does this seem like a reasonable approach to this or have I missed some clever feature of iMacros that would have made my life easier? There does not seem to be a command to determine if a file exists before issuing a FILEDELETE so I have to ensure that the batch file does not call Firefox unless the file is there and I need to be sure nothing else deletes it before the iim Macro does. Otherwise, I seem to get hanging iMacros scripts with error messages.
  2. Is this TAB=1 / TAB CLOSE command pair likely to work as I am expecting it? I have Firefox open with a tab on the home page when this whole process starts and the processing never happens on that first tab; it always opens a new tab, so that part is good. However, I have come back an hour or two later and found an extra tab open at times. I was not expecting TAB=1 to help me, but I thought TAB CLOSE would always close the tab the macro script is working on. Should I add more time before the TAB CLOSE command (or perhaps after it)?
  3. Am I correct that I needed to clone and then rename the iMacros and the upload files or use some other means to ensure that they would not potentially process /delete the same file or otherwise interfere with another instance of the same script? I chose to name the upload files / batch files / iim files Upload1/Upload2/Upload3 for simplicity, but I can imagine that I might have been able to pass a parameter like the file name to a single script (if this is supported) and then always run AWUpload.iim. Is there a way I could have done that?
  4. Is there anything you can suggest to make this process cleaner or more robust?
I appreciate any guidance you can offer. I am not asking you to code this for me. I have tried to learn this on my own even though I am not very technical.

Thanks.
Post Reply