How can I apply one Plack application to another?

I have it:

use Plack::Builder;
my $config_app = sub {...};
my $app = sub {...}

builder {
    mount "/admin" => $config_app;
    mount "/"   => $app;
};

$config_appsaving configuration values ​​to a file app.cfg, and $appits configuration file. Reading the configuration file in each request is not required. You must read it at the beginning of the application and re-read it when it changes.

What is the best way to achieve this?

My only idea: the application will remember the last config_read_time file and in each request will check the modification time app.cfg. If the file has been modified, reread it.

Is this the best solution? (mean some messages between $ config_app and $ app, for example, when $ config_app saved the new configuration will send some message to $app: re-read the config.

+3
source share
2 answers

.

:

use constant MIN_CHECK_DELAY => 5;  #SECONDS
use constant CONFIG_FILE => '/etc/wtf.conf';

{
    my $last_changed = 0;
    my $last_check   = 0;

    sub load_config {

        return if $last_check + MIN_CHECK_DELAY <= time;

        return if (stat(CONFIG_FILE))[9] <= $last_check;

        # Do stuff here.

        return;
    }

}

, , , , .

`load_config() , . , - , . .

, . , .

, , , . rsync , , , , NFS.

: ?

, - .

. - , , snarky . , , . . . . , , . , , .

+5

$app ( ) $config_app, .

, Perl (MyApp:: ConfigFile - ) $app, $config_app singleton. , - . , , - Starman.

+6

All Articles