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

NAME

Dancer2::Plugin::JobScheduler::Client::TheSchwartz - A front to the client of the job scheduler or other object via which the jobs are submitted

VERSION

version 0.006

DESCRIPTION

Internal class.

Not to be used separately. Please see Dancer2::Plugin::JobScheduler.

CONFIGURATION

The configuration of Dancer2::Plugin::JobScheduler::Client::TheSchwartz requires only the knowledge of how to connect with its database backends. TheSchwartz can use simultaneously several databases as backends. When inserting a new task, TheSchwartz loops over all available databases until it finds one that it can connect to and inserts the task there. TheSchwartz client does not maintain its own database handles. Instead, it requires the calling program to give a subroutine pointer or the name and method of a class which can provide the handle.

In a long running process, such as a web service, the database handle can become invalid. Database can close the handle if it stays unused a long period of time. The database handle has to be recreated if that happens.

If callback is a subroutine pointer, then Dancer2::Plugin::JobScheduler will call the given pointer and give one argument: the name of the database it wants to reach.

This example creates two databases and uses a locally defined subroutine to get the database handle:

    use Database::Temp;
    use DBI;
    my %test_dbs = (
        theschwartz_db1 => Database::Temp->new( driver => 'SQLite', );
        theschwartz_db2 => Database::Temp->new( driver => 'SQLite', );
    );
    my $get_dbh = sub {
        my ($id) = @_;
        return DBI->connect( $test_dbs{ $id }->connection_info );
    };
    my %plugin_config = (
        default => 'theschwartz',
        schedulers => {
            theschwartz => {
                package => 'TheSchwartz',
                parameters => {
                    dbh_callback => $get_dbh,
                    databases => [
                        {
                            id => 'theschwartz_db1',
                            prefix => q{},
                        },
                    ]
                }
            }
        }
    );

This example uses the Perl package Database::ManagedHandle to provide an open database handle.

    my %plugin_config = (
        default => 'theschwartz',
        schedulers => {
            theschwartz => {
                package => 'TheSchwartz',
                parameters => {
                    dbh_callback => 'Database::ManagedHandle->instance->dbh',
                    databases => [
                        {
                            id => 'theschwartz_db1',
                            prefix => q{},
                        },
                    ]
                }
            }
        }
    );
        my $get_dbh = sub {
            my ($id) = @_;
            return DBI->connect( $test_dbs{ $id }->connection_info );
        };

Please see Dancer2::Plugin::JobScheduler on how to attach this configuration to the plugin's configuration.

AUTHOR

Mikko Koivunalho <mikkoi@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2023 by Mikko Koivunalho.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.