10 Replies Latest reply on Nov 15, 2011 2:27 PM by DavidJondreau

    Intentional Infinite Loop

    jeepboy

      Hello,

       

      I would love to have a little advice on this situation. I am considering employing an intentional infinite loop in a script - I need the script to search for certain records and if not found wait 5 minutes and then try again. When the records are found it performs certain actions on them. I am considering an infinite loop to accomplish this because we need to check for these records every 5 minutes 24/7.

       

      The basic approach I'm considering is

       

      Go To Layout (contains stop and restart buttons)

      Loop

      Perform find

      If Get(FoundCount) > 0 perform subscript

      Wait 5 minutes

      End Loop

       

      The layout that the script goes to provides buttons for a user to interrupt the process with a stop button as well as one to restart the process along with an Exit/Quit button.

       

      My concern is that I may end up with memory problems after this script has been running for several hours, days or even weeks.

       

      The alternative approach would be to use cron jobs in the Operating System to trigger my script to run every 5 minutes. We use this approach in some other aspects of our system but I'd prefer to not go that route and allow my users to stop and start the process from within the FileMaker system so they don't have to mess around with cron jobs themselves.

       

      Thanks for any advice!

        • 1. Re: Intentional Infinite Loop
          ibrahim_bittar

          Why not to use Install On Timer Script?.

           

          Saludos

           

          Ibrahim Bittar Torres

          Director General

          Eikonsys, S.A. de C.V.

          FileMaker 10 Certified Developer

          http://www.eikonsys.com

          FileMaker Business Alliance

          • 2. Re: Intentional Infinite Loop
            DavidZakary

            Why not use a Server-side script to accomplish this? Set up a schedule that runs every 5 minutes. If it needs to run on a client side computer use an OnTimer script trigger. This should prevent amy memory leaks problems as the script runs and then exits.

            • 3. Re: Intentional Infinite Loop
              jeepboy

              I hadn't considered that.  While I've used FMP for years that's one feature/step I've not used before so I'll check it out.  Thanks!

              • 4. Re: Intentional Infinite Loop
                ariley

                Hi Jeepboy, 

                 

                If you have FileMaker 10 or 11, you can use a timer to run your script in the solution itself on a layout or you can run the script at timed intervals from the server.

                 

                Please let us know what version of FileMaker and server you have so we can advise you further. 

                 

                 

                Regards,

                 

                Agnes B. Riley

                FileMaker 10 and 11 Certified Developer

                http://www.zerobluetech.com

                ZeroBlue Technology Solutions

                where your data goes to work

                 

                Member, FileMaker Business Alliance

                Member, FileMaker Technical Network

                 

                FileMaker Advanced 11.3 on Mac OS X 10.6.8

                 

                "Imagination is more important than knowledge..."

                   /Albert Einstein/

                • 5. Re: Intentional Infinite Loop
                  jeepboy

                  We are on FileMaker 11 so On Timer trigger might be a good route for me.  Trying to read up on that feature/step to get educated as I've not used it before.  Thanks for such quick replies!  I had no idea I'd get help from so many so quickly!

                  • 6. Re: Intentional Infinite Loop
                    RayCologon

                    Hi jeepboy,

                     

                    The basic technique you're considering - a looping script that does its thing 24/7 - is one that has been used in many implementations over the years, and was a mainstay for many developers before server-side scripts were available.

                     

                    I've been involved with quite a few implementations of this kind, and can report that, if set up and deployed appropriately, such a process can be expected to run unattended for an extended period (months at a time if need be). Of course, by deployed approriately, I'm referring to both OS, hardware and environment (UPS etc) considerations as well as the file and script itself.

                     

                    One thing I would suggest is that you have the script run in a separate file that has a file reference to your main solution. And with that, I'd suggest that you have the script write out a detailed log of everything it does, as it goes, so that you have a full breadcrumb trail to verify the history over time. It's also a good idea to run occasional checks, back-up and re-boot as a precaution - perhaps weekly. But we have had more than one client who will let such processes run unattended quite a bit longer without problems.

                     

                    So, in short, yes, the scripting engine is robust enough to support iterative processing, and the basic concept as you've outlined it is both feasible and field-proven. With the advent of OnTimer triggers and server-side scripts, there are other options available according to need, so it's a matter of choosing which approach is the best fit for your current needs.

                     

                    Regards,

                    Ray

                    ------------------------------------------------

                    R J Cologon, Ph.D.

                    FileMaker Certified Developer

                    Author, FileMaker Pro 10 Bible

                    NightWing Enterprises, Melbourne, Australia

                    http://www.nightwingenterprises.com

                    ------------------------------------------------

                    • 7. Re: Intentional Infinite Loop
                      Stephen Huston

                      We use a server-side script scheduled to run every 5 minutes to accomplish this type of thing. Works great with one huge exception:

                       

                      If you have related records on multiple servers (we have 3 locations), a server-side script has no access to any records stored on one of the other installations of FMServer, so it can't update information based on records which don't reside on the server where the script is scheduled.

                       

                      For scripts which must read across multiple servers, you need a robot-client timer script or user/client-triggered script.

                      • 8. Re: Intentional Infinite Loop
                        jeepboy

                        Thanks for all the help!  I have reworked it with the OnTimer step and it's working great.  Much much thanks.

                         

                        A related question - and this is something I can totally live without - in my previous implemention using the infinite loop, I was able to display a countdown on the layout during the 5 minute pause.  Would there be any way of doing something similar using OnTimer?

                         

                        Like I said, I can live without this, but if there's an easy way to show the countdown that would be awesome.

                        • 9. Re: Intentional Infinite Loop
                          RayCologon

                          jeepboy wrote:

                          A related question - and this is something I can totally live without - in my previous implemention using the infinite loop, I was able to display a countdown on the layout during the 5 minute pause.  Would there be any way of doing something similar using OnTimer?

                           

                          Hi jeepboy,

                           

                          Yes, there are a few ways you might approach that, but possibly the easiest and neatest (not to mention least resource intensive) would be to have your OnTimer script, on closing, post a data URL into a web viewer on the layout. The data URL can contain some basic JavaScript to invoke a countdown timer display with appropriate parameters.

                           

                          There are any number of examples of JavaScript code for various types of counters available on the web, so you can make it as fancy as you like. However, I'm attaching an example of a 'basic model' to show you what I mean. This one counts down in seconds from 300 to zero. I've provided a button to set the countdown in motion, but of course in your case the Set Web Viewer[ ] command would be called by script.

                           

                          You should be able to adapt this to suit - or build your own along comparable lines...

                           

                          Regards,

                          Ray

                          ------------------------------------------------

                          R J Cologon, Ph.D.

                          FileMaker Certified Developer

                          Author, FileMaker Pro 10 Bible

                          NightWing Enterprises, Melbourne, Australia

                          http://www.nightwingenterprises.com

                          ------------------------------------------------

                          • 10. Re: Intentional Infinite Loop
                            DavidJondreau

                            Have it run every minute, decrementing a counter on each run, but only running the rest of the script every 5 iterations. Might be annoying if the machine is actually has a user at it.

                             

                            You could also have the script post the "next start time" instead of a countdown. That only needs to happen once every 5 minutes.