Hello! 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. 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. 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. 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. 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. 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.) Is there a way of uniquely identifying 10 Lua scripts that FreeSWITCH launches at startup? Or is there a better way of handling this situation altogether? I'm open to any suggestions that people would care to make! (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.) Mike van Lammeren
May I ask what the end goal is? It could be that there are better tools in the toolbox to help you... -MC On Fri, Mar 5, 2010 at 11:04 AM, Mike van Lammeren <mike@van.lammeren.net>wrote:
Hello!
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.
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.
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.
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.
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.
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.)
Is there a way of uniquely identifying 10 Lua scripts that FreeSWITCH launches at startup?
Or is there a better way of handling this situation altogether? I'm open to any suggestions that people would care to make!
(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.)
Mike van Lammeren
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
I can only talk about the project in vague terms, due to client confidentiality, but here goes: Many thousands of devices will be reporting events, via HTTP Post, to a central server farm. There will be at least 5 or 6 web servers recording these events, and a similar number of VoIP servers running FreeSWITCH. Communication between the web servers and VoIP servers is via a shared MySQL Cluster. Certain events will result in FreeSWITCH originating a phone call, playing a voice message to a human, then recording a number typed in by that human. It is important that each event result in just one phone call. We don't want people bothered with multiple, simultaneous calls, and we don't want things to be missed, either. What do you think? On Fri, Mar 5, 2010 at 2:16 PM, Michael Collins <msc@freeswitch.org> wrote:
May I ask what the end goal is? It could be that there are better tools in the toolbox to help you...
-MC
On Fri, Mar 5, 2010 at 11:04 AM, Mike van Lammeren <mike@van.lammeren.net>wrote:
Hello!
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.
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.
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.
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.
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.
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.)
Is there a way of uniquely identifying 10 Lua scripts that FreeSWITCH launches at startup?
Or is there a better way of handling this situation altogether? I'm open to any suggestions that people would care to make!
(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.)
Mike van Lammeren
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
So much for theory! Take a look at this sample script. -- math.randomseed(os.time()) for i=1,9 do -- final version will loop forever freeswitch.consoleLog("info", "wake-up #" .. i .. ", random number: " .. math.random(111,999) .. "\n") -- Sleep for a while freeswitch.msleep(5000) end freeswitch.consoleLog("warning", "Script end.\n") return 0 If I launch 10 copies of this Lua script with FreeSWITCH, with the 'startup-script' param in lua.conf.xml, then it turns out that each time through the loop for each script does actually produce a unique random number. If I comment out the first line, thus seeding the random number generator, then all 10 scripts give the same 'random' number the first time through the loop, then a unique random number for each subsequent loop! Apparently, I don't really have the problem I thought I had. All the same, I'm still open to suggestions on better ways to achieve my ultimate goals! Mike van Lammeren On Fri, Mar 5, 2010 at 2:32 PM, Mike van Lammeren <mike@van.lammeren.net>wrote:
I can only talk about the project in vague terms, due to client confidentiality, but here goes:
Many thousands of devices will be reporting events, via HTTP Post, to a central server farm. There will be at least 5 or 6 web servers recording these events, and a similar number of VoIP servers running FreeSWITCH. Communication between the web servers and VoIP servers is via a shared MySQL Cluster. Certain events will result in FreeSWITCH originating a phone call, playing a voice message to a human, then recording a number typed in by that human.
It is important that each event result in just one phone call. We don't want people bothered with multiple, simultaneous calls, and we don't want things to be missed, either.
What do you think?
On Fri, Mar 5, 2010 at 2:16 PM, Michael Collins <msc@freeswitch.org>wrote:
May I ask what the end goal is? It could be that there are better tools in the toolbox to help you...
-MC
On Fri, Mar 5, 2010 at 11:04 AM, Mike van Lammeren <mike@van.lammeren.net
wrote:
Hello!
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.
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.
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.
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.
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.
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.)
Is there a way of uniquely identifying 10 Lua scripts that FreeSWITCH launches at startup?
Or is there a better way of handling this situation altogether? I'm open to any suggestions that people would care to make!
(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.)
Mike van Lammeren
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
Thanks so much, everyone! Awesome advice, as usual! Due to a deadline situation, I'm going with the Lua script idea. However, if it gives us any trouble after the looming deadline, then I will definitely go the C route. Thanks again! Mike van Lammeren On Fri, Mar 5, 2010 at 2:42 PM, Brian West <brian@freeswitch.org> wrote:
Write it in C and use the FreeSWITCH task scheduler API.
/b
On Mar 5, 2010, at 1:38 PM, Mike van Lammeren wrote:
All the same, I'm still open to suggestions on better ways to achieve my ultimate goals!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
In case anyone's interested, I just found something cool. You can pass parameters to the Lua script from the lua.conf.xml file, like so: <param name="startup-script" value="temp.lua script1"/> <param name="startup-script" value="temp.lua script2"/> <param name="startup-script" value="temp.lua script3"/> I can see that being useful. Mike van Lammeren On Fri, Mar 5, 2010 at 2:59 PM, Mike van Lammeren <mike@van.lammeren.net>wrote:
Thanks so much, everyone! Awesome advice, as usual!
Due to a deadline situation, I'm going with the Lua script idea. However, if it gives us any trouble after the looming deadline, then I will definitely go the C route.
Thanks again!
Mike van Lammeren
On Fri, Mar 5, 2010 at 2:42 PM, Brian West <brian@freeswitch.org> wrote:
Write it in C and use the FreeSWITCH task scheduler API.
/b
On Mar 5, 2010, at 1:38 PM, Mike van Lammeren wrote:
All the same, I'm still open to suggestions on better ways to achieve my ultimate goals!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
and also you can get the script name from argv[0] if you name you script in different names 2010/3/6 Mike van Lammeren <mike@van.lammeren.net>:
In case anyone's interested, I just found something cool. You can pass parameters to the Lua script from the lua.conf.xml file, like so: <param name="startup-script" value="temp.lua script1"/> <param name="startup-script" value="temp.lua script2"/> <param name="startup-script" value="temp.lua script3"/> I can see that being useful. Mike van Lammeren
On Fri, Mar 5, 2010 at 2:59 PM, Mike van Lammeren <mike@van.lammeren.net> wrote:
Thanks so much, everyone! Awesome advice, as usual! Due to a deadline situation, I'm going with the Lua script idea. However, if it gives us any trouble after the looming deadline, then I will definitely go the C route. Thanks again! Mike van Lammeren
On Fri, Mar 5, 2010 at 2:42 PM, Brian West <brian@freeswitch.org> wrote:
Write it in C and use the FreeSWITCH task scheduler API.
/b
On Mar 5, 2010, at 1:38 PM, Mike van Lammeren wrote:
All the same, I'm still open to suggestions on better ways to achieve my ultimate goals!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
Actually, I don't believe that does work. At least, not on my system. Trying to access argv[0] just produces a lua error about "concatenating a nil value." On Fri, Mar 5, 2010 at 10:28 PM, Seven Du <dujinfang@gmail.com> wrote:
and also you can get the script name from argv[0] if you name you script in different names
2010/3/6 Mike van Lammeren <mike@van.lammeren.net>:
In case anyone's interested, I just found something cool. You can pass parameters to the Lua script from the lua.conf.xml file, like so: <param name="startup-script" value="temp.lua script1"/> <param name="startup-script" value="temp.lua script2"/> <param name="startup-script" value="temp.lua script3"/> I can see that being useful. Mike van Lammeren
On Fri, Mar 5, 2010 at 2:59 PM, Mike van Lammeren <mike@van.lammeren.net
wrote:
Thanks so much, everyone! Awesome advice, as usual! Due to a deadline situation, I'm going with the Lua script idea.
However,
if it gives us any trouble after the looming deadline, then I will definitely go the C route. Thanks again! Mike van Lammeren
On Fri, Mar 5, 2010 at 2:42 PM, Brian West <brian@freeswitch.org> wrote:
Write it in C and use the FreeSWITCH task scheduler API.
/b
On Mar 5, 2010, at 1:38 PM, Mike van Lammeren wrote:
All the same, I'm still open to suggestions on better ways to achieve my ultimate goals!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:
http://lists.freeswitch.org/mailman/options/freeswitch-users
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
The patch was committed on 15433. Though I haven't start to use that. Which version are you on? http://jira.freeswitch.org/browse/MODLANG-122 2010/3/9 Mike van Lammeren <mike@van.lammeren.net>:
Actually, I don't believe that does work. At least, not on my system. Trying to access argv[0] just produces a lua error about "concatenating a nil value."
On Fri, Mar 5, 2010 at 10:28 PM, Seven Du <dujinfang@gmail.com> wrote:
and also you can get the script name from argv[0] if you name you script in different names
2010/3/6 Mike van Lammeren <mike@van.lammeren.net>:
In case anyone's interested, I just found something cool. You can pass parameters to the Lua script from the lua.conf.xml file, like so: <param name="startup-script" value="temp.lua script1"/> <param name="startup-script" value="temp.lua script2"/> <param name="startup-script" value="temp.lua script3"/> I can see that being useful. Mike van Lammeren
On Fri, Mar 5, 2010 at 2:59 PM, Mike van Lammeren <mike@van.lammeren.net> wrote:
Thanks so much, everyone! Awesome advice, as usual! Due to a deadline situation, I'm going with the Lua script idea. However, if it gives us any trouble after the looming deadline, then I will definitely go the C route. Thanks again! Mike van Lammeren
On Fri, Mar 5, 2010 at 2:42 PM, Brian West <brian@freeswitch.org> wrote:
Write it in C and use the FreeSWITCH task scheduler API.
/b
On Mar 5, 2010, at 1:38 PM, Mike van Lammeren wrote:
All the same, I'm still open to suggestions on better ways to achieve my ultimate goals!
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
indeed you are missing something. The FSAPI interface, see the API object in the lua docs and the "luarun" api command. You will probably find this knowledge very useful but even more important you may want to know that high-availability and script do not go together as well as high-availability and C, for instance. On Fri, Mar 5, 2010 at 1:04 PM, Mike van Lammeren <mike@van.lammeren.net>wrote:
Hello!
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.
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.
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.
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.
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.
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.)
Is there a way of uniquely identifying 10 Lua scripts that FreeSWITCH launches at startup?
Or is there a better way of handling this situation altogether? I'm open to any suggestions that people would care to make!
(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.)
Mike van Lammeren
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Anthony Minessale II FreeSWITCH http://www.freeswitch.org/ ClueCon http://www.cluecon.com/ Twitter: http://twitter.com/FreeSWITCH_wire AIM: anthm MSN:anthony_minessale@hotmail.com <MSN%3Aanthony_minessale@hotmail.com> GTALK/JABBER/PAYPAL:anthony.minessale@gmail.com<PAYPAL%3Aanthony.minessale@gmail.com> IRC: irc.freenode.net #freeswitch FreeSWITCH Developer Conference sip:888@conference.freeswitch.org <sip%3A888@conference.freeswitch.org> iax:guest@conference.freeswitch.org/888 googletalk:conf+888@conference.freeswitch.org<googletalk%3Aconf%2B888@conference.freeswitch.org> pstn:+19193869900
Hi Mike, You can spawn a new script with something like api = freeswitch.API(); reply = api:executeString("luarun /tmp/msg.lua"); - and you can pass parameters, accessed in the normal way. 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. Cheers -- Dave ----- Original Message ----- From: Mike van Lammeren To: FreeSWITCH Users Sent: Friday, March 05, 2010 12:04 PM Subject: [Freeswitch-users] Which Lua script am I? Hello! 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. 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. 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. 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. 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. 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.) Is there a way of uniquely identifying 10 Lua scripts that FreeSWITCH launches at startup? Or is there a better way of handling this situation altogether? I'm open to any suggestions that people would care to make! (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.) Mike van Lammeren ------------------------------------------------------------------------------ _______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
participants (6)
-
Anthony Minessale
-
Brian West
-
David Knell
-
Michael Collins
-
Mike van Lammeren
-
Seven Du