POE Application fault tolerance
Hi all, I'm trying to write my application with as much fault tolerance as possible, with that is mind, is if acceptable for a sessions _start subroutine to call: $kernel->delay_set("_start", 60); obviously the _start subroutine will have some logic to prevent it from running any of the "work" subroutines. The basic idea is that if _start can't initialise the session because a database connection fails (for example), it can try again after a set period of time, and 1. it doesn't stop the kernel, and 2. it doesn't stop other sessions from running etc Thanks, -- Peter Farmer
Re: POE not doing what I'm expecting it to......
Thanks to everyone who took the time to reply, I now have a much better understanding of how to write POE applications. Thanks, -- Peter Farmer
Re: POE not doing what I'm expecting it to......
Hi all, Here is some simpler code to illustrate my point... [EMAIL PROTECTED] poe]$ cat test.pl #!/home/pfarmer/local/bin/perl use strict; use warnings; use POE; POE::Session->create ( inline_states => { _start => sub { my $kernel = $_[KERNEL]; $kernel->yield("scheduler"); }, _stop => sub { print "STOP\n"; }, job_runner => sub { print time() . " - Sleeping\n"; sleep(2); }, scheduler => \&sche, } ); sub sche () { print time() . " - Running Scheduler\n"; my $kernel = $_[KERNEL]; $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->yield("job_runner"); $kernel->delay_set("scheduler", 10); } POE::Kernel->run(); exit; [EMAIL PROTECTED] poe]$ perl -v This is perl, v5.8.8 built for i686-linux Copyright 1987-2006, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page. [EMAIL PROTECTED] poe]$ perl ./test.pl 1149783926 - Running Scheduler 1149783926 - Sleeping 1149783928 - Sleeping 1149783930 - Sleeping 1149783932 - Sleeping 1149783934 - Sleeping 1149783936 - Sleeping 1149783938 - Sleeping 1149783940 - Sleeping 1149783942 - Sleeping 1149783944 - Sleeping 1149783946 - Running Scheduler 1149783946 - Sleeping 1149783948 - Sleeping . Now, when I run the script, because of the $kernel->delay_set("scheduler",10) at the end of the "sche" sub, I'm expecting to see "sche" running at about 1149783936 or 1149783938 or as soon as possible after the 10 seconds have passed not 1149783946 once all the other event "job_runners" are finished. My POE version is 0.3501. Sorry to be a pain.. :) -- Peter Farmer
Re: POE not doing what I'm expecting it to......
Hi Nicholas, Thanks for the reply, I was using 1 single session, but then thought the reason the delay time wasn't working was because it was all set in the same session. Basically the file is created with a list of networks in it, the script then deletes it once it has read them all in. The idea is that "someone" drops a file into the directory, the script reads it and schedules the rbl lookups on the networks in the file, the results are then written to a file somewhere else (yet to be coded). I was initially using delay, but again tried alarm_set to see if that worked instead, it didn't and I didn't change it back. I'm still fairly confused because having spoken to the nice ppl in #poe on irc.perl.org I've been told that it should work as I'm expecting but its not :( Thanks for looking :) -- Peter Farmer On 08/06/06, Nicholas Perez <[EMAIL PROTECTED]> wrote: Hi Peter, I don't think I would organize this the way it's been done. You are basically providing the same code refs to two different sessions for starters. This could easily be done with a single session and using something like POE::Wheel::FollowTail, so that anytime there is new input appended to the file, your events would get called. I don't know how your input file gets generated, but I assume it is just a log file that keeps growing if the file remains existent. If you are set on doing it this way, I would aggregate your two sessions into one. No real need to have two sessions. Also, your email mentions one way of delayed events and your code uses another. Which one are you using? I am not exactly sure alarm_set over and over again is what you want to do. See POE::Kernel. Just some things to think about. On 6/8/06, Peter Farmer <[EMAIL PROTECTED]> wrote: > On 08/06/06, Peter Farmer <[EMAIL PROTECTED]> wrote: > > Hi all, > > > > I'm fairly new to coding with POE, and I think I've not quite grasped > > the concepts correctly. > > > > I have a script which has two sessions, the first session is what I > > call a scheduler session, basically it reads the content of a txt file > > and "schedules" events into the other session with > > > > $kernel->post("worker","job_runner",$arg); > > > > the scheduler session then runs a > > > > $kernel->delay_set("scheduler", 10); > > > > What I'm expecting to happen is that the worker session chugs through > > the events its been posted, but after 10 seconds the scheduler session > > runs again to check the content of txt file and post more events to > > the worker if needed. Basically what happens is that the worker > > session chugs through it entire queue and then the scheduler runs > > again. > > > > Is there a way to get what I want to happen to happen? > > > > > > > > Thanks, > > > > -- > > Peter Farmer > > > > Hi again, > > pastebins of the code: > > http://poundperl.pastebin.com/767423 > http://poundperl.pastebin.com/767424 > >
Re: POE not doing what I'm expecting it to......
On 08/06/06, Peter Farmer <[EMAIL PROTECTED]> wrote: Hi all, I'm fairly new to coding with POE, and I think I've not quite grasped the concepts correctly. I have a script which has two sessions, the first session is what I call a scheduler session, basically it reads the content of a txt file and "schedules" events into the other session with $kernel->post("worker","job_runner",$arg); the scheduler session then runs a $kernel->delay_set("scheduler", 10); What I'm expecting to happen is that the worker session chugs through the events its been posted, but after 10 seconds the scheduler session runs again to check the content of txt file and post more events to the worker if needed. Basically what happens is that the worker session chugs through it entire queue and then the scheduler runs again. Is there a way to get what I want to happen to happen? Thanks, -- Peter Farmer Hi again, pastebins of the code: http://poundperl.pastebin.com/767423 http://poundperl.pastebin.com/767424 Thanks, -- Peter Farmer
POE not doing what I'm expecting it to......
Hi all, I'm fairly new to coding with POE, and I think I've not quite grasped the concepts correctly. I have a script which has two sessions, the first session is what I call a scheduler session, basically it reads the content of a txt file and "schedules" events into the other session with $kernel->post("worker","job_runner",$arg); the scheduler session then runs a $kernel->delay_set("scheduler", 10); What I'm expecting to happen is that the worker session chugs through the events its been posted, but after 10 seconds the scheduler session runs again to check the content of txt file and post more events to the worker if needed. Basically what happens is that the worker session chugs through it entire queue and then the scheduler runs again. Is there a way to get what I want to happen to happen? Thanks, -- Peter Farmer