The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

return the exception message This method can be used to catch the exception if the code used already contained a try catch

Method that manage the timeout on a dancer request

NAME

Dancer::Plugin::TimeoutManager - Plugin to define route handlers with a timeout

SYNOPSIS package MyDancerApp;

  use Dancer;
  use Dancer::Plugin::TimeoutManager;

  # if somecode() takes more than 1 second, execustion flow will be stoped and a 408 returned
  timeout 1, 'get' => '/method' => sub {
      somecode();
  };

  #if header X-Dancer-Timeout is set, the header's value is used as the timeout
  timeout 'get' => '/method' => sub {
    my $code;
  };

DESCRIPTION

This plugins allows to define route handlers with a maximum amount of time for the code execution.

If that time is elapsed and the code of the route still runs, the execution flow is stopped and a default 408 response is returned.

If the timeout is set to 0, the behavior is the same than without any timeout defined.

It's also possible to define route handlers that will set a per-request timeout protection, depending on the value of the header X-Dancer-Timeout.

If config variable max_timeout set - timeouts will be limitet to be no more than c<max_timeout> value. If no timeout set, max_timeout is ignored.

Also environment variable DISABLE_DANCER_TIMEOUT can be used to turn off all timeouts in Dancer application.

If your Dancer code already use try catch, the exeption may be catched. So exception_message method can be used to cath the content of the exception in your Dancer code.

AUTHOR

Frederic Lechauve, <frederic_lechauve at yahoo.fr>

COPYRIGHT AND LICENSE

Copyright (C) 2014 by Weborama

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.2 or, at your option, any later version of Perl 5 you may have available.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 37:

Unknown directive: =method

Around line 49:

Unknown directive: =method