[Dancer-users] do something after sending response
Tyler Durden
tylerdu at bounced.me
Sat Aug 13 20:25:38 CEST 2011
On 12.08.2011 11:52, Alex Knowles wrote:
> On Thu, 2011-08-11 at 17:54 +0100, Nick Knutov wrote:
>> Hello all,
>>
>> is it possible to run some code after sending response to upstream [and
>> closing socket] with Dancer?
>>
>> For example: I want to get request, send response and after closing
>> socket to back-end do some job with big timeouts: write logs, send
>> notifications via emails, etc.
>>
>
> Further to all the other answers. We use TheSchwartz quite heavily in
> our main (non dancer) environment. It's a little hairy, but a job queue
> (not necessarily TheSchwartz) may well be what you want...
>
I used a similar approach, to solve the same problem as OP, but I used
beanstalk job queue. http://kr.github.com/beanstalkd/
It worked great, it's very fast and efficient, there are client
libraries for all popular languages (including Perl, of course).
It solves the problem of forking, but you still have to serialize data
you want to send to your workers (processes doing stuff for you). What I
liked is multiple tubes (in beanstalk nomenclature) - you can have one
tube for logging, and another one for sending emails etc... And also
persistance, beanstalkd (written in C, so very fast) can log job
requests to file, so you won't lose any, even if you reboot server!
Beanstalk is also very simple and easy to use, took me no longer than an
hour to install it, configure it, modify original (PHP) code to dispatch
requests to beanstalk, and write a simple worker (Perl) to just log some
stuff to database. Logging AFTER the response has already been sent to
web visitor. Yay! :)
--
tydu
More information about the Dancer-users
mailing list