stevieb has asked for the wisdom of the Perl Monks concerning the following question:
Update: I've solved the issue. Everything defined/created in the app that is NOT referenced within at least one route goes out of scope when the app is started. If something is referenced within a route even just once, it lives. Even my forking code works now :)
I'm still working on my Dancer2 application, but now I'm at the point where I need it to periodically to something, even without client interaction. Essentially, I want the Dancer2 app to behave like a normal always-running background script while a client browser is not attached.
So, what I need to do is have this app periodically do something without tying up the main application. I wrote a *very* basic async timed event module Async::Event::Interval (yeah, for fun, mostly). It works, and does what I need it to do (the event is a forked process). Here's an example:
use warnings; use strict; use Async::Event::Interval; my $event = Async::Event::Interval->new( 1, # interval, in seconds sub { print "event...\n"; }, ); $event->start; sleep 1; # wait for first event to fire print "main is going to sleep...\n"; sleep 5; print "done\n";
Output:
event... main is going to sleep... event... event... event... event... event... done
I fetch the PID of the event process, and it shows up just dandy as running in the proc list:
$ ps ax | grep 22834 22834 pts/2 S+ 0:00 perl t/evt.pl
However, no matter where it is I create and start the event in a Dancer2 app, it fires after the first interval is expired, but then in the proc list I see:
$ps ax | grep 22732 22732 pts/2 Z+ 0:00 [/home/spek/repo] <defunct>
Can anyone explain what Dancer2 is doing that forces a child process to become defunct, or how I can get around/avoid this problem without having to have a second background app running to do the side-work that is needed? If anyone thinks a different async type software will work, I'll ditch my own, as it was just for playing around anyways.
As a side note, I have no idea why it's showing /home/spek/repo in the proc entry, as my current working dir is ~/repo/app-envui when I start the webapp.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Async timed events with Dancer2
by Anonymous Monk on Sep 25, 2016 at 02:17 UTC | |
by stevieb (Canon) on Sep 25, 2016 at 13:37 UTC | |
|
Re: Async timed events with Dancer2
by stevieb (Canon) on Sep 25, 2016 at 14:32 UTC |