Hi Jeff, On Thu, Oct 19, 2017 at 10:28 AM, Jeffrey Kain via 4D_Tech < 4d_tech@lists.4d.com> wrote:
> ... > all it's doing is waiting for a relatively rare condition to happen (and a > record to appear in this table). It might happen at most once or twice per > day, maybe only once every few days, but when it happens it has to be dealt > with immediately. It's such a waste to be constantly querying for a record > that 99999 times out of 100000 won't exist. > An approach I use in these cases is (I'm using pseudo code and this off the top of my head): // Handle_rare_condition (critical param{;internal param}) Case of :(Count parameters=1) // Write $1 to the [Message table} $id:=Execute on server(Current method name;0;Current method name;$1;Current process;*) Resume process($id) :(Count parameters=2) // this part is executing on the server $done:=false While(Not($done)) All Records([Message table]) Loop ([Message table]) -- do important stuff Pause process(Current process) End while End case When Handle_rare_condition is called with one param it writes that param to the Message Table. Then it calls itself on the server. Execute on server will either start the process, if it isn't already there, or since I included the trailing * simply return the id of the existing process, which if it exists is probably paused. Resume process($id) is ignored if the process isn't paused (like when you just created it). Otherwise it wakes it up. On the server side $1 is pretty much ignored in this case. $2 might be useful (I use this same form on Clients for spawning processes so knowing the parent process number can be useful for messaging). In this case you could make $1 a magic number of some sort to indicate the part of the code running on the server. Or you could write the [Message table] record first and then call this method without any params to initiate it and the parent process as $1 to indicate the server code. Whatever, the bottom part of the method starts a loop on the server which sounds like it could get all records for [Message table], loop them and do the important stuff. Then just go back to sleep. As someone else suggested this could be called from a trigger on [Message table] to run whenever one of those records was created. This would not involve any queries. I like putting the spawning and execution of server side methods in one method. All the important stuff is in one place. -- Kirk Brooks San Francisco, CA ======================= *The only thing necessary for the triumph of evil is for good men to do nothing.* *- Edmund Burke* ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **********************************************************************