<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18876">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2 face=Arial>Hi Mike,</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>You can spawn a new script with something
like</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>api = freeswitch.API();<BR>reply =
api:executeString("luarun /tmp/msg.lua");<BR></FONT></DIV>
<DIV><FONT size=2 face=Arial>- and you can pass parameters, accessed in the
normal way.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>So there's no reason why you couldn't have a
background script running which spawns one worker per task that needs doing;
each worker can do its task and then exit.</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Cheers --</FONT></DIV>
<DIV><FONT size=2 face=Arial></FONT> </DIV>
<DIV><FONT size=2 face=Arial>Dave</DIV></FONT>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: black"><B>From:</B>
<A title=mike@van.lammeren.net href="mailto:mike@van.lammeren.net">Mike van
Lammeren</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A
title=freeswitch-users@lists.freeswitch.org
href="mailto:freeswitch-users@lists.freeswitch.org">FreeSWITCH Users</A>
</DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Friday, March 05, 2010 12:04
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [Freeswitch-users] Which Lua
script am I?</DIV>
<DIV><BR></DIV>Hello!
<DIV><BR></DIV>
<DIV>I am working on a high-availability system and need a Lua script that can
run in the background and loop forever, periodically waking up to accomplish
some tasks. I would like to be able to handle at least 10 concurrent
tasks.</DIV>
<DIV><BR></DIV>
<DIV>My first idea was to have a simple background script that would call
another script, let's call it the 'task' script, every 5 seconds or so. This
would spread the work around, and if any task script quit with an error, the
background script would remain running, and would continue to launch new task
scripts.</DIV>
<DIV><BR></DIV>
<DIV>However, I can see no way for the background script to launch other Lua
scripts. Am I missing something? I need something like session:execute(), but
unfortunately this background script has no session, and I'm not sure if
session:execute() can even make a call like the "luarun" console
command.</DIV>
<DIV><BR></DIV>
<DIV>So, my next ideas was to have 10 copies of the background script. Each
script would loop forever. Upon launch, each script would perform a single
task, then sleep for 60 seconds. This allows handling of 10 concurrent
tasks.</DIV>
<DIV><BR></DIV>
<DIV>However, there are some problems with running 10 copies of the same
script, which I believe can be solved if each script could be given a unique
identifier. One problem is that I would like the scripts to actually sleep for
a variable amount of time, say between 55 and 65 seconds, so that the workload
would spread around. Another, similar problem, is that each script needs to
'claim' a number of database records from a table that is queuing up work for
the scripts. Once again, if each script had a unique identifier, then I could
use an update query to effectively 'set and test' a record that would be tied
to that script instance.</DIV>
<DIV><BR></DIV>
<DIV>I could use a random number to identify each script, but since
math.random is seeded with a timestamp that only resolves to seconds, then all
10 scripts will be given the same sequence of random numbers, and all 10 will
run in lock-step with each other. So, random numbers are out. (If I had a
unique ID to seed the random number generator, then I could just use that
unique ID and wouldn't need random numbers.)</DIV>
<DIV><BR></DIV>
<DIV>Is there a way of uniquely identifying 10 Lua scripts that FreeSWITCH
launches at startup?</DIV>
<DIV><BR></DIV>
<DIV>Or is there a better way of handling this situation altogether? I'm open
to any suggestions that people would care to make!</DIV>
<DIV><BR></DIV>
<DIV>(I would entertain the idea of a single script that would start with
FreeSWITCH, then launch 10 other scripts, giving each a unique identifier, but
that brings me back to the original problem of not knowing how to launch other
Lua scripts under FreeSWITCH.)</DIV>
<DIV><BR></DIV>
<DIV>Mike van Lammeren</DIV>
<DIV><BR></DIV>
<P>
<HR>
<P></P>_______________________________________________<BR>FreeSWITCH-users
mailing
list<BR>FreeSWITCH-users@lists.freeswitch.org<BR>http://lists.freeswitch.org/mailman/listinfo/freeswitch-users<BR>UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users<BR>http://www.freeswitch.org<BR></BLOCKQUOTE></BODY></HTML>