2 Replies Latest reply on Jun 16, 2017 1:23 AM by FabianK007

    Same script simultaneously on two FM session/instances

    FabianK007 Level 1

      Hi everybody,


      I have an issue with a rather big script.


      Here is what the script does:

      1. it runs over a *.ditamap and rearranges the many *.xml files into a few *.fm files for a new *.book
      2. a specific titlepage.fm is added into the *.book
      3. TOC and index are generated and included as well
      4. formats and definitions are imported from a specific variable.fm into to book.

      The script works fine until there is more than one FM instance running it, i.e, until I use FrameMaker Publishing Server 2015, which runs a few FM instances simultaneously.


      Here is what goes wrong:

      1. FM instance 'a' imports titlepage.fm from any other FM instance running
      2. the import is not applied on every *.fm file of the book.

      Result: the books have the wrong titles pages, sometimes also the wrong footer and colors.


      The script is ExtendScript and does not contain any app.ActiveDoc.

      During the run, files are generated under \AppData\Local\Temp, could the mix occur due to a dissociation issue with those files?

        • 1. Re: Same script simultaneously on two FM session/instances
          4everJang Level 3

          I think your intuition about multiple instances overwriting each other's files is the right explanation for this.


          Your script should probably create a new temp folder to store its files, then remove that temp folder when it is done. Use a timestamp as the name for the temp subfolder - that ensures that your multiple FM instances are not overwriting each other's files.


          Good luck



          • 2. Re: Same script simultaneously on two FM session/instances
            FabianK007 Level 1

            Thank you for the tip.

            The script applies an xslt. Since I didn't write the template (13pages!) and I'm not comfortable with xslt, I didn't manage to create a separate tempfolder for each ditamap.

            My workaround in ExtendScript is to make other instances wait until the transformation is done. Looks a bit like this:



            var FrameMakerLock=new File("D:\\FrameMakerLock.txt");
            while(FrameMakerLock.exists) {
              $.sleep (5000);
              if(FrameMakerLock.exists) {
              var content = FrameMakerLock.read()
              var olddate = new Date(content.split("\n")[0]);
              var datediff = (new Date() - olddate)/60000; //datediff in minutes
              if (datediff > 20) FrameMakerLock.remove(); //remove the lock because it was created over 20 minutes ago
            //create the lock then start Publish
            //write a date in the lockfile
            //so other instances can check the age
            FrameMakerLock.writeln(new Date().toUTCString());
            //start the xslt
            //remove the lock