Rocco,

thanks for the reply.  I afraid I'm being thick and|or I was unclear.  Don't
your changes require a client?

I want to have a process that runs routinely and on demand.  I want it to
run routinely, regardless if there is a client connected or not.  When the
client requests, I want to run the routine immediately.

Jay
"Rocco Caputo" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Sun, Aug 24, 2003 at 05:07:09PM -0500, Jake wrote:
> > Hi,
> >
> > if I have (roughly) the code below.  I can interact with the server from
a
> > client, but is there anyway for me to get the server to run
"some_process()"
> > routinely, __without__ any client interaction.
> >
> > Thanks
> > Jay
> >
> > #!/usr/bin/perl
> >
> > use warnings;
> > use strict;
> > use POE qw(Component::Server::TCP);
> > use Net::Server::Daemonize qw(daemonize);
> >
> > daemonize('nobody','nobody','/var/mydaemon.pid');
> >
> > POE::Component::Server::TCP->new(
> >     Address         => "localhost",
> >     Port            => 12345,
> >     ClientFilter    => "POE::Filter::Reference",
> >     ClientInput     => \&clientInput
>       ClientConnected => \&start_routine_process,
>       InlineStates    => {
>         do_routine_process => \&some_process,
>       },
> > );
> >
> > $poe_kernel->run();
> >
> > sub clientInput {
> >     my ( $heap, $list ) = @_[ HEAP, ARG0 ];
> >     my @symbol = ref $list eq "ARRAY" ? @$list : $list;
>       my @list;
>       push @{$heap->{things_to_do}}, [EMAIL PROTECTED];
> > }
>
>   sub start_routine_process {
>       $_[HEAP]->{things_to_do} = [ ];  # start with an empty list
>       $_[KERNEL]->delay(do_routine_process => 60);  # check it in a minute
>   }
>
> > sub some_process {
>       my ($kernel, $heap) = @_[KERNEL, HEAP];
>       while (my $next_thing = shift @{$heap->{things_to_do}}) {
>           $heap->{client}->put("@$next_thing");
>       }
>       unless ($heap->{shutdown}) {
>           $kernel->delay(do_routine_process => 60);
>       }
> > }
>
> What's going on here?
>
> When the client connects, start_routine_process() sets a timer called
> "do_routine_process" for sixty seconds in the future.  It also
> initializes a job queue in the session's heap.
>
> Every time the "do_routine_process" timer goes off, some_process() deals
> with everything in the job queue.  It also sets another timer for sixty
> seconds in the future, but only if the connection has not been shut
> down.  This effectively polls for jobs once a minute, as long as the
> client is connected.  It also guarantees that all enqueued jobs are
> handled.
>
> Caveat utilitor, or some junk: I haven't tested any of the above code.
>
> --
> Rocco Caputo - [EMAIL PROTECTED] - http://poe.perl.org/


Reply via email to