NAME
POE::Component::Cron - Schedule POE Events using a cron spec
SYNOPSIS
use POE::Component::Cron;
use DateTime::Event::Crontab;
use DateTime::Event::Random;
$s1 = POE::Session->create(
inline_states => {
_start => sub {
$_[KERNEL]->delay( _die_, 120 );
}
Tick => sub {
print 'tick ', scalar localtime, "\n";
},
Tock => sub {
print 'tock ', scalar localtime, "\n";
}
_die_ => sub {
print "_die_";
}
}
);
# crontab DateTime set
$sched1 = POE::Component::Cron->add(
$s1 => Tick => DateTime::Event::Cron->from_cron('* * * * *')->iterator(
span => DateTime::Span->from_datetimes(
start => DateTime->now,
end => DateTime::Infinite::Future->new
)
),
);
# random stream of events
$sched2 = POE::Component::Cron->add(
$s2 => Tock => DateTime::Event::Random->(
seconds => 5,
start => DateTime->now,
)->iterator
);
$sched3 = POE::Component::Cron-> from_cron(
'* * * * *' => $s2->ID => 'modify'
);
# delete some schedule of events
$sched2->delete();
DESCRIPTION
This component encapsulates a session that sends events to client sessions on a schedule as defined by a DateTime::Set iterator. The implementation is straight forward if a little limited.
This is early Beta code. The API is close to jelling. I'd love to hear your ideas if you want to share them.
METHODS
spawn
No need to call this in normal use, add, new and from_cron all crank one of these up if it is needed. Start up a poco::cron. returns a handle that can then be added to.
add
Add a set of events to the schedule. the 'session and event name are passed to POE without even checking to see if they are valid and so have the same warnnigs as ->post() itself.
$cron->add(
session,
'event_name',
DateTime::Set->iterator,
@other_args_to_event\@session
);
from_cron
Add a schedule using a simple syntax for plain old cron spec.
POE::Component::Cron-> from_cron('* * * * *' => session => event);
delete
remove a schedule. you did hang on to the handle returned by add didn't you?
SEE ALSO
POE, perl, DateTime::Set, DateTime::Event::Cron.
AUTHOR
Chris Fedde, <cfedde@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2007 by Chris Fedde
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.